C#第二章

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只有15个有效位,不是信着想开多大开多大的。。。

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();
        }
    }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值