日期:2014-05-17  浏览次数:20685 次

关于int和int?,赋值null
本帖最后由 zpzhangwenhan 于 2013-01-10 17:00:24 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Person p = new Person();
            p.Age = null;
            p.Age2 =null;
        }
    }

    public class Person
    {
        public int? Age
        {
            get;
            set;
        }
        public int Age2
        {
            get;
            set;
        }
 
    }
}



int 不能赋值为null
int? 能赋值为null
这是怎么回事
这两种类型有什么不同???

------解决方案--------------------
引用:
这两种类型有什么不同??? 

一个是人民币,另外一个是花人民币买来的东西,你说有什么不同?

完全不同。虽然这些东西也可以变现,但是它毕竟不人民币,而只是可以当作商品交换的物品而已。