C#語法學習三(Method)

作者: Athrun  來源: 博客園  發布時間: 2008-09-05 15:56  閱讀: 4284 次  推薦: 0   原文鏈接   [收藏]  
 
[1] C#語法學習三(Method)
[2] C#語法學習三(Method)
[3] C#語法學習三(Method)
Code
//簡單方法的應用,沒有帶參數
using System;
namespace Athrun
{
    class Method
    {
        public static void MyMethod()
        {
            Console.WriteLine("this is a method");
        }
        static void Main()
        {
            MyMethod();
        }
    }
}

 

 

Code
//有返回值的方法
using System;
namespace Athrun
{
    class Method
    {
        public static DateTime MyMethod()
        {
            return DateTime.Now;
        }
        static void Main()
        {
            Console.WriteLine("Now time is {0}",MyMethod());
        }
    }
}

 

 

Code
//帶參數的方法
using System;
namespace Athrun
{
    class Method
    {
        public static void MyMethod(string aName)
        {
            Console.WriteLine("this Name is " + aName + "\n");
        }
        static void Main()
        {
            string s=" 帶參數的方法";
            MyMethod(s);
        }
    }
}

//帶參數的方法
using System;
namespace Athrun
{
    class Method
    {
        public static void MyMethod(string aName)
        {
            Console.WriteLine("this Name is " + aName + "\n");
        }
        static void Main()
        {
            string TempName="";
            while (TempName!="end")
            {
                TempName=Console.ReadLine();
                MyMethod(TempName);
            }
        }
    }
}

//帶參數的方法
using System;
namespace Athrun
{
    class Method
    {
        public static int add(int i,int j)
        {
            return i+j;
        }
        static void Main()
        {
            int i=5;
            int j=3;
            Console.WriteLine("i+j=" + add(i,j));
        }
    }
}

 

0
0
 
標簽:C# Method
 
 

文章列表

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()