Non-read only alternative to anonymous types

前端 未结 6 1518
误落风尘
误落风尘 2020-11-29 09:02

In C#, an anonymous type can be as follows:

method doStuff(){
     var myVar = new {
         a = false, 
         b = true
     }

     if (myVar.a) 
     {         


        
6条回答
  •  清歌不尽
    2020-11-29 09:45

    In C# 7 we can leverage named tuples to do the trick:

    (bool a, bool b) myVar = (false, true);
    
    if (myVar.a)
    {
        myVar.b = true;
    }
    

提交回复
热议问题