Powered by Blogger.

Saturday, February 15, 2014

How to set enum values with spaces in c#.net?

In this post we will discuss about how to set enum values with space in C#.Net. Also you can check out:

- Method Overloading in C#.Net

- Readonly textbox value lost on postback asp.net

- Tutorial on MVVM with WPF

If you want to declare enum without giving any space, then you can check out this article.

But If you will give space and declare like below then it will give error.

public enum MonthYear
       Jan 2014 = 0


Here the error will come because of space between Jan 2014.

So below is the syntax to declare enum values with space.

 public enum MonthYear
        [EnumMember(Value = "Jan 2014")]
        Jan2014 = 0,
        [EnumMember(Value = "Feb 2014")]
        Feb2014 = 0,