📜  如何在c#代码示例中生成随机唯一id

📅  最后修改于: 2022-03-11 14:49:21.234000             🧑  作者: Mango

代码示例1
public Random a = new Random(); // replace from new Random(DateTime.Now.Ticks.GetHashCode());
                                // Since similar code is done in default constructor internally
public List randomList = new List();
int MyNumber = 0;
private void NewNumber()
{
      MyNumber = a.Next(0, 10);
      while(randomList.Contains(MyNumber))
        MyNumber = a.Next(0, 10);
}