1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Collections;
 6 
 7 namespace ConsoleApplication1
 8 {
 9        
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             try
15             {
16                 int a = 5;
17                 Console.WriteLine(int.MaxValue);
18 
19                 long b = 52326523222;
20                 Console.WriteLine(long.MaxValue);
21 
22                 //a = checked((int)b);
23 
24                 checked
25                 {
26                     a = (int)b;
27                 }
28 
29                 Console.WriteLine(a);
30             }
31             catch(OverflowException e)
32             {
33                 Console.WriteLine(e.ToString());
34                 Console.ReadLine();
35                 return;
36             }
37 
38             Console.ReadLine();
39         }
40     }
41 }
View Code

 以上是值类型的转换。

 

Type t = f.GetType();      // t的类型为Apple

 

is 和 as 操作符: is操作符返回true;as强制类型转换;

 

posted on 2018-05-28 20:59  zzunstu  阅读(167)  评论(0编辑  收藏  举报