怎么给int数据类型赋值为null
来源:百度知道 编辑:UC知道 时间:2024/06/09 04:02:40
int是值类型,不能为null;
int?是“可空int”,是引用类型,可以为null。
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? i=null