学会了调用方法

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

方法必须有一个返回值(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;

            }
        }

      
              
    }
 
}

posted @ 2008-09-05 14:18  kin2321  阅读(116)  评论(0编辑  收藏  举报