Write a program to create ‘MyClass’ with Random data member, Static Constructor, GetValue() method to return the Random number. Create instances for MyClass and try to retrieve values. Display the results on a Console application.
class MyClass
{
static Random ran;
static int n;
static MyClass()
{
ran = new Random();
}
public int GetValue()
{
n = ran.Next();
return n;
}
}
static void Main(string[] args)
{
MyClass obj = new MyClass();
int Num = obj.GetValue();
Console.WriteLine(Num);
Console.ReadLine();
}
No comments:
Post a Comment