学会了调用方法

创造了一个类,对象化,然后调用

方法必须有一个返回值(int,string)或Void

如 public int firstMethod()

using System;
using System.Collections.Generic;
using System.Text;

namespace test5
{
    class Example
    {
        static void Main()
        {
          
            dgx gg = new dgx();
            int c = gg.firstMethod();
            Console.WriteLine(c);
            Console.Read();
             
                      

              
        }
        class dgx
        {
            public int firstMethod()
            {
                int myField = 42; // ok
                return myField;

            }

            public int anotherMethod()
            {
                int myField = 52; // ok
                return myField;

            }
        }

      
              
    }
 
}

原文地址:https://www.cnblogs.com/bluewelkin/p/1285114.html