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:



Table Of Contents