例如,這SecurityProtocol
屬性可以使用OR
來賦值:迭代收集和使用OR操作分配給每個爲單屬性
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
現在,如果我們想通過移動應用程序中的不硬編碼這個任務它將AppSettings作爲逗號分隔的字符串,如"192,768,3072"
,我們如何將字符串轉換爲枚舉並使用OR
運算符將其分配給屬性?
您可以將整數轉換爲枚舉值:var x =(SecurityProtocolType)192;'。此外,你可以一起使用'|'整數,你可以用逗號分割字符串,並且可以用'Int32.Parse()'分析整數。 –