如题所述
//private修饰çåªè½å¨ç±»æç»æå
é¨è¢«è°ç¨ï¼public修饰çå¯ä»¥å¨ç±»æç»æçå¤é¨è¢«è°ç¨ã
//çä¾åã
using System;
namespace Demo
{
class Program
{
public static void Main(string[] args)
{
//F3æ¯publicçï¼å¯ä»¥å¨ç±»Tçå¤é¨è°ç¨
T.F3();
//é误ï¼ä¸è½å¨ç±»Tçå¤é¨è°ç¨F1ï¼å 为F1æ¯privateç
//T.F1();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
class T
{
private static void F1()
{
Console.WriteLine("T.F1");
}
static void F2()
{
Console.WriteLine("T.F2");
//å¨ç±»Tçå é¨å¯ä»¥è°ç¨ç±»Tçææå½æ°æåï¼ä¸ç®¡ç§æä¸ç§æ
T.F1();
}
public static void F3()
{
Console.WriteLine("T.F3");
}
}
}
//çä¾åã
using System;
namespace Demo
{
class Program
{
public static void Main(string[] args)
{
//F3æ¯publicçï¼å¯ä»¥å¨ç±»Tçå¤é¨è°ç¨
T.F3();
//é误ï¼ä¸è½å¨ç±»Tçå¤é¨è°ç¨F1ï¼å 为F1æ¯privateç
//T.F1();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
class T
{
private static void F1()
{
Console.WriteLine("T.F1");
}
static void F2()
{
Console.WriteLine("T.F2");
//å¨ç±»Tçå é¨å¯ä»¥è°ç¨ç±»Tçææå½æ°æåï¼ä¸ç®¡ç§æä¸ç§æ
T.F1();
}
public static void F3()
{
Console.WriteLine("T.F3");
}
}
}
温馨提示:答案为网友推荐,仅供参考