官术网_书友最值得收藏!

Out variables

With C# 7.0, we can write cleaner code when using out variables. As we know, to use out variables, we have to first declare them. With the new language enhancement, we can now just write out as a prefix and specify the name of the variable that we need that value to be assigned to.

To clarify this concept, we will first see the traditional approach, which is shown as follows:

public void GetPerson() 
{ 
  int year; 
  int month; 
  int day; 
  GetPersonDOB(out year, out month, out day); 
} 
 
public void GetPersonDOB(out int year, out int month, out int day ) 
{ 
  year = 1980; 
  month = 11; 
  day = 3; 
} 

And here with C# 7.0, we can simplify the preceding GetPerson method, which is shown as follows:

public void GetPerson() 
{ 
  GetPersonDOB(out int year, out int month, out int day); 
} 
主站蜘蛛池模板: 开江县| 海南省| 辽阳市| 治县。| 弋阳县| 新宁县| 义马市| 正定县| 临沂市| 邯郸县| 广东省| 宜兰市| 绥德县| 屏东县| 镇江市| 玉林市| 格尔木市| 古田县| 建始县| 龙井市| 莆田市| 双峰县| 高雄市| 山东| 奇台县| 岑溪市| 秦皇岛市| 满城县| 育儿| 肥城市| 太仆寺旗| 海宁市| 陆良县| 卓尼县| 宝鸡市| 玉屏| 伊宁市| 望江县| 云南省| 太和县| 邢台市|