Associate an Alias to Resolve Conflicts

suggest change

If you are using multiple namespaces that contain classes with the same name (such as System.Random and UnityEngine.Random), you can use an alias so that Random refers to one of them without writing the full namespace at each use.

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 type by its fully qualified name:

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

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

rnd is a System.Random. unityRandom is the int returned by UnityEngine.Random.Range, not a UnityEngine.Random instance.

Feedback about page:

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



Table Of Contents