Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am using LINQ to access the list data of sharepoint in vs c#,

the column type in list data is choice(menu to choose from)

i want to insert inside the list data a choice of yes or no from CheckBox of asp.net controls.

The question is how to convert bool to enum?

for example to change the string value to enum and insert it to enum we use

vEnumList(of type enum)=(vEnumList)Enum.Parse(typeof(vEnumList),TextBox1.Text)_

the method of Enum.Parse takes two argument System.Type and string but i want to pass bool value instead of string

Any idea??
Posted

1 solution

How would you expect to convert from a bool to an enum?

An enum is int based, and can have a wide variety of values (2^32 of them!) while a bool is restricted to two values: true and false

There is no default conversion from a bool to an int of any type, enum or not.

You could possibly write method that did it, or just use the "?" operator:
C#
MyEnum me = myBool? MyEnum.Value1 : MyEnum.Value2;
But to be honest, I can't help thinking there is something wrong with your design if you think you need this.
 
Share this answer
 
Comments
Albarhami 14-Oct-12 5:54am    
Thank you Griff,, i will redesign it to avoid so,, but i thought there could be a solution somehow!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900