C# initialiser conditional assignment

后端 未结 6 1258
广开言路
广开言路 2021-01-04 01:49

In a c# initialiser, I want to not set a property if a condition is false.

Something like this:

ServerConnection serverConnection = new ServerConnect         


        
6条回答
  •  醉梦人生
    2021-01-04 02:21

    You can't do this; C# initializers are a list of name = value pairs. See here for details: http://msdn.microsoft.com/en-us/library/ms364047(VS.80).aspx#cs3spec_topic5

    You'll need to move the if block to the following line.

提交回复
热议问题