Q
已棄用c#
24
A
回答
37
當然,你可以:
public enum EE
{
A,
[Obsolete]
B
}
1
-1
正如其他海報指出,你可以添加ObsoleteAttribute
到枚舉成員,但它仍然可以在您的代碼中使用。沒有辦法以編程方式排除枚舉成員,即如果它存在於枚舉中,則會產生編譯錯誤或異常。添加屬性只會向開發人員發出警告。
+5
這是不正確的,有一個屬性[IsError](http://msdn.microsoft.com/en-us/library/system.obsoleteattribute.iserror.aspx),如果爲true,將導致它成爲編譯器錯誤而不是警告。 – 2013-06-18 14:29:04
27
實際上,可能會生成編譯器警告或編譯器錯誤。
public enum TestEnum
{
A,
[Obsolete("Not in use anymore")]
B,
[Obsolete("Not in use anymore", true)]
C,
}
public class Class1
{
public void TestMethod()
{
TestEnum t1 = TestEnum.A; //Works just fine.
TestEnum t2 = TestEnum.B; //Will still compile, but generates a warning.
TestEnum t3 = TestEnum.C; //Will no longer compile.
}
}
無論你使用[Obsolete]屬性,這都可以工作。
相關問題
- 1. 已棄用C#的App.config?
- 2. C功能已被棄用
- 3. C#Threading.Suspend已廢棄,線程已被棄用?
- 4. [棄權] MultiJson.decode已棄用
- 5. 已棄用HttpClient?
- 6. Enum.ToString()已棄用?
- 7. 已棄用Httpclient
- 8. FAXCOMEXLIB已棄用?
- 9. stringWithContentsOfFile已棄用
- 10. DLR:IAttributesCollection已棄用?
- 11. UIPopoverController已棄用
- 12. 'itemFromNormalSprite:selectedSprite:target:selector:'已棄用
- 13. ISampleGrabber已棄用?
- 14. 已棄用notification.setLatestEventInfo
- 15. LSOpenApplication已棄用?
- 16. AndroidHttpClient已棄用
- 17. SetTimer已棄用?
- 18. glEnableClientState已棄用
- 19. CursorAdapter已棄用?
- 20. File.toURL()已棄用?
- 21. getch已棄用
- 22. setFont已棄用?
- 23. Config.LOGD已棄用
- 24. AccountManager.removeAccount已棄用
- 25. OnCameraChangeListener()已棄用
- 26. setBackgroundColor已棄用
- 27. $ HADOOP_HOME已棄用
- 28. ProgressDialog已棄用
- 29. 棄用:函數eregi()已棄用
- 30. SoftLayer_User_Customer :: updatePassword已棄用
您是否嘗試過使用['ObsoleteAttribute'](http://msdn.microsoft.com/en-us/library/system.obsoleteattribute.aspx)? – 2011-12-21 10:58:27
需要看一些代碼... – BoltClock 2011-12-21 10:58:32
@BoltClock爲什麼?我只是想設置一個枚舉爲過時... – JohnJohnGa 2011-12-21 10:59:37