在C#的初始化器中,如果条件为false,我想要不设置属性。
类似于这样的代码:
类似于这样的代码:
ServerConnection serverConnection = new ServerConnection()
{
ServerInstance = server,
LoginSecure = windowsAuthentication,
if (!windowsAuthentication)
{
Login = user,
Password = password
}
};
可以做到吗? 怎么做?
ServerConnection
类的工作方式,如果你的构造函数分配了除null
以外的默认属性值,并且你希望保留这些值用于Login
或Password
,那么这种方法可能行不通。 - xr280xr