Bassem has already provided the Convert.ToInt code
I have already provided a link to MSDN for how to form an If...else construct.
Personally I don't care for the MSDN search implication through Bing. I find that if I need to search for something on MSDN that google is the better tool. Searching for "MSDN" plus my need usually takes me right to the answer.
"MSDN textbox.text" as in this example:
http://www.lmgtfy.com/?q=MSDN+textbo...UTF-8&oe=UTF-8
While Samishii and I have slightly varying preferences on details of searching, the underlying concept remains the same: Check the MSDN.
In the case of the OP's original need though I suspect that he simply did not know what to search for. If one knows so little of C# as to
not know there is an if...else construct for making decisions then what would you search for to solve the original question?
Look at the original question:
i have form contain label this label contents is string and i want to convert it to integer (ex:the label may have male or female i want to put 1 for male and 0 for female using if else)to be used as inputs to neural network
The OP feels that he needs to *convert* the contents of the label from a string to an int. It almost sounds as if (s)he is unaware that a label has .text property... or that there will be no actual *conversion* of the label's text but rather the need to use the .text in the decision making process to then set an int variable to either 1 or 0.
Sure we could just give him/her the one line required:
- int MaleFemale = Textbox1.text.ToLower() == "male" ? 1 : 0 ;
or even a more familiar form:
- int MaleFemale = 0; // set to female unless changed
-
if Textbox1.text.ToLower() == "male" MailFemale = 1;
But let's be honest with him/her and ourselves. The OP needs to learn the basics of C# - and do some simple exercises and walk before trying to run. If he cannot be bothered with that much, then we do him a disservice by answering the most basic of questions such as this. Because then we become a crutch to lean on. Why learn the language when someone else will answer every little question?
How do I add two ints together?
How do programmatically set the text of a label?
How do tell if a checkbox is checked?
It is my own personal opinion and I do not speak for Bytes management when I say:
If a person can't be bothered to take upon themselves the most basic of reading, the most basic of tutorials, the most basic of books, the most basic of responsibility for their own education and career path, then why would I be bothered to take their education or the problem more seriously than they themselves do?