Correct method of a “static” Random.Next in C#?

前端 未结 11 2231
执念已碎
执念已碎 2020-12-10 10:51

Why do i need to create an instance of Random class, if i want to create a random number between 1 and 100 ....like

Random rand = new Random();
rand.Next(1,1         


        
11条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 11:18

    Creating a short-lived instance in C# is almost free. Don't waste your time worrying about this. You probably have better places to look for perf or memory gains.

提交回复
热议问题