201507 C#初級班-傳值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static public void function(int a)
{
a = 5;
Console.WriteLine("a:" + a.ToString());
}
static void Main(string[] args) //static靜態 void 不回傳值 Main 進入點
{
int a = 1;
function(a);
Console.WriteLine("a:" + a.ToString() + "\n");
Console.ReadKey();
}
}
}
result: a=5 ,a=1
解釋:a=1,前面的funtion不影響main裡的結果,因為值已經被寫入
Comments
Post a Comment