C# Else
hi there
I am new to C# and all programming and know very little
i need a way of, if a string is given a value different from any of the things you have said (sorry it's hard to explain) then it says something. else only works for one thing
for example
here is if i use else
string1 = System.Console.In.ReadLine
if (string1.ToLower("yes");
{
System.Console.Out.WriteLine("hello");
}
if (string1.ToLower("no");
{
System.Console.Out.WriteLine("oh my");
}
else
{
System.Console.Out.WriteLine("what?");
}
the else is only for the no
how do i make it an else for if you don't write "yes" or "no"
thanks (and very sorry for the bad explanation)
if you can understand what i mean you are a god
:-)
I am new to C# and all programming and know very little
i need a way of, if a string is given a value different from any of the things you have said (sorry it's hard to explain) then it says something. else only works for one thing
for example
here is if i use else
string1 = System.Console.In.ReadLine
if (string1.ToLower("yes");
{
System.Console.Out.WriteLine("hello");
}
if (string1.ToLower("no");
{
System.Console.Out.WriteLine("oh my");
}
else
{
System.Console.Out.WriteLine("what?");
}
the else is only for the no
how do i make it an else for if you don't write "yes" or "no"
thanks (and very sorry for the bad explanation)
if you can understand what i mean you are a god
:-)
0
Comments
Google is your friend, in terms of programming you should be able to find ALL the basics there fairly easily by searching for a keyword with C#, for example: take your title of this "C# else". If you google that, the fifth result links to the following:
http://www.dummies.com/how-to/content/examining-the-c-else-statement.html
The first result brings you to the offical site for all c# coding, microsoft's MSDN
http://msdn.microsoft.com/en-us/library/5011f09h(VS.80).aspx
This site has everything you need for programming in C# although at times it is a bit difficult to understand for the novice programmer. Just looking around for tutorials on the "else statement" should help you out dramatically. Personally, I always look for real code examples with the sites I find to determine which would be the best resource.
Now to answer your question on this post, use the else if statement. I am not going to tell you the exact code for this, but instead I hope that you utilize what I just told you about google. One of the biggest parts of programming is going and learning new things, researching how to use different keywords and what the syntax (think grammar) is of a language.
For starters, try using this tutorial:
http://csharp.net-tutorials.com/basics/introduction/
When it comes down to it though, the best way to learn it is to find examples and then get your hands dirty by playing around with it as much as you can.
The book I use is published be Dietel and Dietel, it's pretty good. Mine is C++, but they probably have one for C#, too.