Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C# 标识符


C# 标识符

所有 C# **变量** 必须用 **唯一名称** 进行 **标识**。

这些唯一名称称为 **标识符**。

标识符可以是短名称(如 x 和 y)或更具描述性的名称(如 age、sum、totalVolume)。

**注意:** 建议使用描述性名称,以便创建易于理解和维护的代码。

示例

// Good
int minutesPerHour = 60;

// OK, but not so easy to understand what m actually is
int m = 60;

自己试试 »

变量命名的通用规则如下:

  • 名称可以包含字母、数字和下划线字符(_)
  • 名称必须以字母或下划线开头
  • 名称应以小写字母开头,并且不能包含空格
  • 名称区分大小写("myVar" 和 "myvar" 是不同的变量)
  • 保留字(如 C# 关键字,例如 intdouble)不能用作名称

C# 练习

通过练习测试自己

练习

创建一个名为 myNum 的变量,并将其值设置为 50

  = ;

开始练习


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.