Associate an Alias to Resolve Conflicts

suggest change

If you are using multiple namespaces that may have same-name classes(such as System.Random and UnityEngine.Random), you can use an alias to specify that Random comes from one or the other without having to use the entire namespace in the call.

For instance:

using UnityEngine;
using System;

Random rnd = new Random();

This will cause the compiler to be unsure which Random to evaluate the new variable as. Instead, you can do:

using UnityEngine;
using System;
using Random = System.Random;

Random rnd = new Random();

This doesn’t preclude you from calling the other by it’s fully qualified namespace, like this:

using UnityEngine;
using System;
using Random = System.Random;

Random rnd = new Random();
int unityRandom = UnityEngine.Random.Range(0,100);

rnd will be a System.Random variable and unityRandom will be a UnityEngine.Random variable.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Using Directive:
* Associate an Alias to Resolve Conflicts

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
59 Using Directive
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script