Language BASICS (project structure, data type, variables, constants)

Source: Internet
Author: User

         数据类型→变量→运算符→表达式→语句

一.项目结构

.cs---    源文件(程序代码)

.csproj---项目文件(管理文件项)

.sln---   解决方案文件(管理项目)

.config---配置文件

函数的四要素:名称、输入、输出、加工。

主函数  

          static void Main(string[] args)     

           //args 可以自己随便更改名称      {          主函数内容          }

输入语句  

           string s = Console.Readline("");

           //读取一行数据,并赋值给s

输出语句

    Console.Write("要输出的内容");  

    Console.Writeline("要输出的内容");   

     //Write 与Writeline 的区别:Writeline输出后自动换行

常用快捷键:

;    语句结束

//    注释一行

/*    注释一段区域*/

shift delete   删除一行

ctrl k,c   注释选中行

ctrl k,u   取消注释选中行

Alt →     提示,更改

ctrl X     剪切一整行

ctrl V    粘贴一整行

 

二.数据类型
1.值类型
(1)整型:有符号整型和无符号整型。

        区别是无符号整型要比有符号整型的正数范围大。2X+1

        有符号整型:sbyte,short,int,long  带有正负数,范围按所写依次增大

        无符号整型:byte,ushort,uint,ulong  只有正数,范围也是依次增大

 (2)浮点型:float, double, decimal

 (3)字符型(Unicode类型):char=‘hello world!’

(4)布尔型:boll(ture,false)(判断用T or F )

 (5)字符串型:string(用双引号“”)

       String 等同于字符型的概念,长度较长,定义时需要用双引号

(6)日期时间型:datetime

(7)枚举类型:Enum E{......}形的用户定义类型

(8)结构类型:Struct S{......}形式的用户定义类型

2.引用类型

(1)字符串型:string(用双引号“”)

       String 等同于字符型的概念,长度较长,定义时需要用双引号

(2)类类型:Object(所有其他类型的最终基类)

                   Class C{......}形式的用户自定义类型

(3)接口类型:Interface I{......}

(4)数组类型:分为一维和多维数组,例如int[](一组整数)和int[,](两组整数)

示例:

三.变量

1.变量的命名规则:

(1)变量名组成:字母、数字、下划线、@、汉字

(2)首字符只能是字母、下划线、@、汉字
(3)不能与系统关联字重名
2.变量定义:
数据类型 变量名[=值]
//[]内的内容不是必填
示例:int a =1
3.变量的使用:赋值、取值

四.常量

1.分类:符号常量、字面常量

2.符号常量的定义:

变量声明前加关键字const

示例:const int a =3

3.符号常量的使用:不能赋值,只能取值

4.转义字符:

‘\t‘         tab键字符

‘\\‘         反斜线

‘\’‘          单引号

‘\“‘         双引号

‘\n‘         换行

‘\r‘         回车

 

语言基础(项目结构、数据类型、变量、常量)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.