using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("The first App in Begining C# Program!");
Console.Readkey();
}
}
}
折叠预处理
#region
……
……
#endregion
(折叠中间部分)
转义字符:为了将字面值赋给变量不出错
eg:
string myString = ““string” is”;
整数
sbyte [-128, 127] 8位
byte [0, 255] 8位
short [-32 768, 32767] 16位
ushort [0, 65535] 16位
int [-2 147 483 648, 2 147 483 647] 32位
uint [0, 4 294 967 296] 32位
long [9 223 372 036 854 775 808, 9 223 372 036 854 775 807] 64位
ulong [0, 18 446 744 073 709 551 615] 64位
浮点
前两种存储类型:+/- m x 2^e
后一种存储方式:+/- m x 10^e
类型 m-min m-max e-min e-max
float 0 2^24 -149 104
double 0 2^53 -1075 970
decimal 0 2^96 -28 0
文本和布尔
char [0, 65 535]
bool ture/false
string 没有上限
1、变量名的第一个字母必须是字母、下划线或@
2、其后可以是字母、下划线或数字
3(注意)变量名不能是关键字
类型 后缀
int, uint, long, ulong 无
uint、ulong u或U
long、ulong l或L
ulong (u、l 位置关系和大小写不影响)Ul,Lu……均可
float f或F
double 无、d或D
decimal m或M
@置于字符串最前端,无需转义,即可正确存储和表达字面值
比较运算符
==、!=、<、>、<=、>=
条件运算符
&&、| |
赋值运算符
=、+=、-=、*=、/=、%=、&=、|=、^=
其他
一元:++、–,+(正)、-(负)
三元:逻辑表达式?a:b
逻辑表达式成立,三元表达式值为a,否则为b
二元:+、-、*、/……
优先级
(优先级记忆不用担心,因为写代码时一般会使用括号指定优先级,增加可读性)
1、前缀:++,–,一 元:+,-
2、,/,%
3、+,-
4、>>、<<
5、>、<、>=、<=
6、==, !=
7、&
8、^
9、|
10、&&
11、| |
12、=,+=,-=,=,/=、<<=、>>=、&=、|=、^=
后缀:++,–
该部分同c
三元运算符
<test>? <resultIfTrue> : <resultIfFalse>
if语句
if (<test>)
<code executed if <test> is true>;
或
if (<test>)
<code executed if <test> is true>;
else
<code executed if <test> is false>;
[效果同三元运算符]
或
if (varl == 1)
{
// Do something.
}
else if (varl == 2)
{
// Do something else.
}
else
{
// Do something else.
}
switch语句
switch (<testVar>)
{
case <comparisonVal1>:
<code to execute if <testVar> == <comparisonVal1> >
break;
case <comparisonVal2>:
<code to execute if <testVar> == <comparisonVal2> >
break;
……
case <comparisonValN>:
<code to execute if <testVar> == <comparisonValN> >
break;
default:
<code to execute if <testVar> != <comparisonVals> >
break;
}
do循环
do
{
<code to be looped>
}while (<Text>)
while循环
while (<Text>)
{
<code to be looped>
}
for循环
for (<initialization>; <condition>; <operation>)
{
<code to loop>
}
无限循环
while (ture)
{}
for (; ;)
{}
……
(<destinationType>) <sourceVar>
enum <typeName>:<underlyingType>
{
<value1> = <actualVal1>
<value2> = <actualVar2>
……
<valueN> = <actualVarN>
}
(数据默认为int类型,每个值根据顺序定义【从0开始】)
声明新类型的变量
<typeName> <varName>
<varName> = <typeName>.<value>;
struct <typeName>
{
<memberDeclarations>
}
<memberDeclarations>
<accessibility> <type> <name>
定义结构类型的变量类似枚举
可以通过句点字符访问这个组合变量中的数据成员
数组的索引是从0算起,如果要查找数组中第三个元素,语法为:myArray[2]
<baseType> [ ] <name>
(必须在访问之前初始化)
举例
int [] myIntArray = {1, 2, 3};
或,int [] myIntArray = new int[arraySize];
arraySize可以是常数,也可以是变量
或,int [] myIntArray = new int[10] {2, 5, 5};
foreach循环
遍历数组中每一个元素
foreach (<baseType> <name> in <array>)
{
// can use <name> for each element
}
多维数组
[, ] ;
与一位数组类似,只是使用的时候需要更多的逗号和更多的大括号,数据在内存中顺序存储
eg:double [, ] hillHight = new double[3, 4] {{2, 3 , 4, 5}, {2, 33, 55.7, 5}, {2, 5}};
数组的数组
声明:int[ ] [ ] jaggedIntArray;
jaggedIntArray = new int [2] [ ];
jaggedIntArray [0] = new int [3];
jaggedIntArray [0] = new int [2];
//或是下面这样
jaggedIntArray = new int [3] [ ]{
new int [2] {2, 4}, new int [3] {2, 3, 4},
new int [1] {5} };
int [ ] [ ] jaggedIntArray = new int [3] [] {
new int [2] {2, 4}, new int [3] {2, 3, 4},
new int [1] {5} };
foreach (int [ ] sonArray in fatherArray)
{
foreach (int sprit in sonArray)
{
// work;
}
}
<stringName>. ToCharArray( )
【其后方法使用方式一致】,有返回值Length( )
,有返回值ToUpper( )
, ToLower( )
,有返回值TrimStart( )
, TrimEnd( )
, 有返回值PadLeft(<length>,<char> )
, PadRight(<length> , <char>)
, 有返回值,默认添加空格static <returnType> <FunctionName>( <type> <typeName>)
{
// do something.
return <typeVar>
}
如果是void类型,则之间return; 或省略不写
如果方法有返回值,在方法体内,所有情况下,都必须有返回内容,否则会报错 “并不是所有的处理路径都用返回值”
针对一行代码的方法,可以使用 表达式体方法(expression-bodied method)处理
如:
static double Multiply (double myVal1, double myVal2)
{
return myVal1 * myVal2;
}
可改写为:
static double Multiply (double myVal1, double myVal2) => myVal1 * myVal2;
To be continue……
转载请注明出处(周更)。
本文地址:https://blog.csdn.net/buyaozhongwe/article/details/107299240
如对本文有疑问, 点击进行留言回复!!
mysql中如何实现 row_number分组求topN的功能
SQLSERVER中RANK OVER(PARTITION BY)的用法
Kaspersky Endpoint Security 10 for Windows version 10.2.6.3733 is no longer supported
网友评论