我是C#的新手并不熟悉它。我对new PostpaidProfile();
和default(AutoliftResult);
的区别感到困惑。我的意思是它们的调用方式有何不同。下面是我不知道的类或对象是什么叫
public class PostpaidProfile
{
public bool WasRetrieved { get; set; }
public string AccountCategory { get; set; }
public string AccountNum { get; set; }
public string Acd { get; set; }
public string ActivationDate { get; set; }
public int? AgingDays { get; set; }
public decimal? CreditRating { get; set; }
public string CutOff { get; set; }
public string Cycle { get; set; }
public bool? IsBlacklisted { get; set; }
public bool? IsNopsa { get; set; }
public decimal? Msf { get; set; }
public string RatePlan { get; set; }
public string ServiceStatus { get; set; }
public int? VipCode { get; set; }
public string Zip { get; set; }
public string Remarks { get; set; }
}
public class AutoliftResult
{
public bool IsSuccess { get; set; }
public decimal StatusCode { get; set; }
public string Message { get; set; }
public string SRNumber { get; set; }
}
以及它们如何被称为
PostpaidProfile output = new PostpaidProfile();
AutoliftResult output = default(AutoliftResult);
我的问题是他们的区别是什么? (我不是在谈论他们的内容)如果我宣布AutoliftResult output = new AutoliftResult();
答案 0 :(得分:6)
new PostpaidProfile()
创建一个新的类实例。
default(AutoliftResult)
为指定的类型创建默认值。对于参考类型,它是null
。对于值类型,通常是0
转换为类型的任何内容 - 即,如果类型为int
,则默认值为0
;如果type为bool
,则默认值为false
等。
答案 1 :(得分:2)