C#is strongly(强)typed(operation on variable type)
原来强类型语言是为了好debug个cut
C#is statically and stronglytyped,Good thing for cuts down bugs.
类型方面与c语言不同的地方
char | 2 | Char | Unicode字符 |
double | 8 | Double | +/–5.0 x10-324 to approximately +/–1.8 x 10308 , 15 to 16 significant figures(15-16个有效位) |
金融运算方面
decimal | 16 | Decimal | Fix-precision, 28-29位有效数字和小数点位置,金融 (-7.9 x 1028 to 7.9 x 1028) / (100 to 28) |
细节方面看来还是很多需要注意的
Console.WriteLine("Hello World!");
float someFloat = 57f;
decimal someDecimal=57.4m;
char c = 'A';
Console.WriteLine(someFloat);
Console.WriteLine(someDecimal);
Console.WriteLine((int)c);
Console.ReadKey();
using double , float and decimal for nonintergervalue.
float someFloat = 57
f;
decimal someDecimal=57.4
m;
‘
A’ : unicode
\u0041
枚举的级别和类的级别一样,可以自定义数据类型,可以在枚举名称后使用“:”来指明枚举类型
所以将枚举类型放到main中会报错。。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hello_world.cpp
{
class Program
{
enum Temperatures : int //指定基类型
{
WickedCold = 0,
FreezingPoint = 32,
LightJacketWeather = 60,
SwimmingWeather = 72,
BoilingPoint = 212,
}
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
System.Console.WriteLine("{0}", Temperatures.BoilingPoint);
System.Console.WriteLine("{0}", (int)Temperatures.BoilingPoint);
Console.ReadKey();
}
}
}
foreach的用法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hello_world.cpp
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
int[] array1 = new int[5];
int[] array2 = { 1, 3, 5, 7, 9 };
foreach (int cur in array1)
System.Console.WriteLine(cur);
foreach (int cur in array2)
System.Console.WriteLine(cur);
Console.ReadKey();
}
}
}
预处理器
#define DEBUG
//#undef DEBUG
只能放在文件的最开始引用掉的部分的添加与否决定后面到底编译哪块代码
#define DEBUG
//#undef DEBUG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hello_world.cpp
{
class Program
{
static void Main(string[] args)
{
#if DEBUG
System.Console.WriteLine("Hello World!");
#else
System.Console.WriteLine("Hello World!");
#endif
Console.ReadKey();
}
}
}