We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Monday, June 22, 2015

   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: