一. 標(biāo)識(shí)符與關(guān)鍵字

1.標(biāo)識(shí)符

using System;
namespace WelcomeYou
{
    //"歡迎你“的控制臺(tái)程序
    class Program
    {
        static void Main(string[] args)
        {
            //定義輸出文本變量
            string welcomeText = "歡迎你";
            //輸出文本輸出到控制臺(tái)
            Console.WriteLine(welcomeText);
            //讓控制臺(tái)程序可見(jiàn)用戶(hù)輸入,并停留
            Console.ReadKey();
        }
    }
}

像WelcomeYou,Program,Main,welcomeText就標(biāo)識(shí)符,(值得注意的事,習(xí)慣上c#變量名采用駝峰法命名,其他的采用帕斯卡法命名)。

ps:
駝峰法:首個(gè)單詞首字母小寫(xiě),后面的單詞首字母大寫(xiě)。
帕斯卡法:首個(gè)單詞首字母大寫(xiě),后面的單詞首字母大寫(xiě)。

標(biāo)識(shí)符不允許數(shù)字開(kāi)頭,開(kāi)頭必須是_或者字符開(kāi)頭(包括漢語(yǔ)字符)。標(biāo)識(shí)符不能和關(guān)鍵字一樣,如果要使用關(guān)鍵字作為標(biāo)識(shí)符,前面要加@,比如@class.
按照習(xí)慣來(lái)說(shuō),標(biāo)識(shí)符的命名要有意義,(對(duì)類(lèi)的成員命名的時(shí)候一般都是名詞,方法一般都是動(dòng)詞)。


2.關(guān)鍵字

在C#里面關(guān)鍵字事不能作為標(biāo)識(shí)符存在。在前面的代碼中namespace,class ,static ,string 都是為關(guān)鍵字。
官方文檔

C#中有77個(gè)常規(guī)關(guān)鍵字

abstract as base bool break
byte case catch char checked
class const continue decimal default
dekegate do double else enum
event explicit extern false finally
fixed float for foreach goto
if implicit in int interface
internal is lock long namespace
new null object operator out
override params private protected public
readonly ref return sbyte sealed
short sizeof stackalloc static string
struct switch this throw true
try typeof unit ulong unchecked
unsafe ushort using virtual void
volatile while

還有25個(gè)上下文關(guān)鍵詞

add alias ascending async await
descending dynamic from get global
group into join let orderby
partial (type) partial (method) remove select set
value var where where yield
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容