Linked Questions
90 questions linked to/from Convert a string to an enum in C#
77
votes
4
answers
139k
views
Casting string to enum [duplicate]
I'm reading file content and take string at exact location like this
string fileContentMessage = File.ReadAllText(filename).Substring(411, 3);
Output will always be either Ok or Err
On the other ...
18
votes
4
answers
32k
views
Cannot convert string to Enum type I created [duplicate]
I have an enum:
public enum Color
{
Red,
Blue,
Green,
}
Now if I read those colors as literal strings from an XML file, how can I convert it to the enum type Color.
class TestClass
{
...
3
votes
6
answers
3k
views
Cast a String to an Enum Tag in C# [duplicate]
Possible Duplicate:
How do I Convert a string to an enum in C#?
How to Convert (to Cast) a string ( a text) to be Enum tag value in C#
1
vote
2
answers
18k
views
How to Use Enum in switch case for comparing string- C# [duplicate]
I have one enum like below
public enum Colors
{
red,
blue,
green,
yellow
}
I want to use it switch case
public void ColorInfo(string colorName)
{
switch (colorName)
{
...
2
votes
4
answers
601
views
How to conver a string to a enum of type int? [duplicate]
Possible Duplicate:
How do I Convert a string to an enum in C#?
I have an enum of type int:
public enum BlahType
{
blah1 = 1,
blah2 = 2
}
If I have a string:
string something = "...
5
votes
4
answers
841
views
How do I convert a string to an enum value to an integer? [duplicate]
Possible Duplicate:
How do I Convert a string to an enum in C#?
Enums returning int value
I have declare an enumeration:-
public enum Car
{
SELECT = 0,
AUDI = 1,
...
5
votes
3
answers
637
views
Convert from String to Enum return not valid cast in WPF [duplicate]
I trying to convert from WPF combobox selected value to enumurator it return not valid cast in the runtime otherwise the string and the enum name is matched my code is
Siren.PfundMemberWebServices....
-3
votes
1
answer
9k
views
Using enums and switch c# [duplicate]
I have some problems with using enums with switch.My task is to enter the name of the country and then show which part of the world is that one. I can't read enums from the keyboard.Did I make ...
2
votes
6
answers
1k
views
Refactoring switch statement to enum [duplicate]
I would like to clean my code and make it more simple. Now I've got a method which returns and int value.
private int ReturnMyValue(string line)
{
switch (line)
{
case "ST":
...
0
votes
1
answer
2k
views
How do i convert "Monday" to the integer 1 and "Tuesday" to 2 etc all the way to friday? [duplicate]
I have a user inputting a day (Monday) and a week number in order to search for a value in an array. However, to get the array output, I need the row and column numbers. The row number can be obtained ...
4
votes
2
answers
271
views
How can I cast a String to an Enum [duplicate]
I have the following code:
public string GetSetting(string setting)
{
return db2.ExecuteScalar<string>("SELECT VALUE FROM Setting WHERE SettingType = ?", setting);
}
public enum NOA
{
...
0
votes
1
answer
1k
views
Enums: Retrieve enum value from enumeration name string [duplicate]
The enum:
public enum EnumName
{
Gary = 1,
Dave = 2
}
The input:
string inputValue = "Gary";
What is the best way to retrieve the value from the enum for this string? I.e. return the value 1....
2
votes
1
answer
2k
views
Changing Colors on Markers [duplicate]
I am trying to import a file with a list of latitude and longitude coordinates. In Visual C#, and using GMAP.NET, a marker is placed for every coordinate pair. I want multiple files to be able to be ...
1
vote
1
answer
825
views
How to pass an enum that I created from view to controller using FormCollection in Asp.Net MVC [duplicate]
So now I can retrieve a string and integer
by doing this for string
LastName = formCollection["LastName"]
and for int
Amount = int.Parse(formCollection["Amount"])
My problem now is for enum. I ...
-4
votes
1
answer
850
views
How to get integer values from Enum in c# [duplicate]
I have an Enum
public enum MyEnum
{
value1= 1,
value2= 2,
value3= 3,
value4= 4
}
How do I get the integer values , if I give the string as input , say
input--&...