您的位置:知识库 »

C#语法学习三(Method)

作者: Athrun  来源: 博客园  发布时间: 2008-09-05 15:56  阅读: 4661 次  推荐: 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

热门文章

    最新文章

      最新新闻

        热门新闻