make barcode with vb.net 5: Branching in Visual C#.NET

Generate Code 128 in Visual C#.NET 5: Branching

5: Branching
Paint Code 128B In Visual C#
Using Barcode maker for VS .NET Control to generate, create Code 128B image in VS .NET applications.
www.OnBarcode.com
Recognizing Code 128 Code Set B In Visual C#.NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
case "Progressive": Console.WriteLine("You voted Progressive.\n"); break; default: Console.WriteLine("You did not make a valid choice."); break; } Console.WriteLine("Thank you for voting."); } } }
Creating Linear In C#
Using Barcode creator for .NET Control to generate, create 1D Barcode image in VS .NET applications.
www.OnBarcode.com
Drawing UCC - 12 In Visual C#.NET
Using Barcode maker for VS .NET Control to generate, create USS-128 image in .NET applications.
www.OnBarcode.com
ReadLine( ) and Input
Code 128B Drawer In Visual C#
Using Barcode printer for Visual Studio .NET Control to generate, create Code 128 Code Set B image in Visual Studio .NET applications.
www.OnBarcode.com
UPC-A Supplement 2 Generation In Visual C#
Using Barcode generation for .NET Control to generate, create UPC-A image in .NET applications.
www.OnBarcode.com
In 3, you learned how to use WriteLine( ) to output messages to the console. Up until now, though, we haven t shown you how to get any input from your users. The looping statements that we ll introduce in the next section often go well with user input, so we ll cover that now. C# has a ReadLine( ) statement that corresponds to WriteLine( ), and as you might guess, it reads in a string from the console into a string variable. The use of ReadLine( ) is rather simple. To take input from the console and assign it to the string inputString, you d do this:
Barcode Creator In C#.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
USPS Confirm Service Barcode Creator In C#.NET
Using Barcode generator for Visual Studio .NET Control to generate, create USPS Confirm Service Barcode image in VS .NET applications.
www.OnBarcode.com
string inputString; inputString = Console.ReadLine( );
Code 128C Encoder In .NET
Using Barcode drawer for .NET framework Control to generate, create Code 128 image in Visual Studio .NET applications.
www.OnBarcode.com
ANSI/AIM Code 128 Creation In None
Using Barcode creator for Office Excel Control to generate, create Code 128C image in Excel applications.
www.OnBarcode.com
Whatever the user types at the console, until he presses Enter in other words, one line is assigned to inputString. It usually helps to give the user a prompt to let him know what he should be entering at a ReadLine( ), so it makes sense to start with a WriteLine( ):
Draw 1D Barcode In VB.NET
Using Barcode generation for .NET Control to generate, create 1D image in .NET framework applications.
www.OnBarcode.com
EAN13 Generation In Objective-C
Using Barcode encoder for iPhone Control to generate, create EAN 13 image in iPhone applications.
www.OnBarcode.com
Console.WriteLine("Enter your input string.") inputString = Console.ReadLine( );
UPC-A Supplement 2 Scanner In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Barcode Decoder In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Often, though, you ll want the user to enter his input on the same line, immediately after the prompt. In that case, you can use Write( ) instead of WriteLine( ). Write( ) outputs text to the console, the same as WriteLine( ), but it doesn t send a newline character. In other words, if you follow a Write( ) with a ReadLine( ), the cursor waits at the end of the output for the user s input:
Barcode Encoder In Java
Using Barcode generation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
PDF-417 2d Barcode Reader In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Console.Write("Enter your name here: "); string userName = Console.ReadLine( );
Draw EAN128 In Java
Using Barcode maker for BIRT Control to generate, create EAN 128 image in BIRT applications.
www.OnBarcode.com
QR Code Generator In .NET Framework
Using Barcode creation for Reporting Service Control to generate, create QR image in Reporting Service applications.
www.OnBarcode.com
You ll notice that ReadLine( ) accepts only a string, which can be a problem if you want your user to enter a number that you want to calculate with. C# will happily accept the number, but as a string, and you ll quickly find that C# doesn t implicitly convert from string to int, for example. So, this won t work:
Barcode Creator In None
Using Barcode generator for Online Control to generate, create Barcode image in Online applications.
www.OnBarcode.com
Print Code 39 Full ASCII In None
Using Barcode printer for Office Word Control to generate, create Code 39 Extended image in Word applications.
www.OnBarcode.com
Console.Write("Enter your age: "); string myInt = Console.ReadLine( );
ReadLine( ) and Input |
if (myInt >= 18) Console.WriteLine("You may buy a ticket.");
Fortunately, this is an easy problem to fix. You just need to convert the string to an int32 type, and for that, C# offers the Convert class. You can fix the error in the code we just showed you like this:
Console.Write("Enter your age: "); string inputAge = Console.ReadLine( ); int myInt = Convert.ToInt32(inputAge); if (myInt >= 18) Console.WriteLine("You may buy a ticket.");
You can even combine the input and conversion into a single step, like this:
int myInt = Convert.ToInt32(Console.ReadLine( ));
The Convert class can convert to a number of classes, including ToInt32 (and various other types of int), ToDouble, ToBoolean, ToChar, and ToString. However, there are some limitations, most of which are easy to predict. You can convert a char to a string easily (you get a string with just one character), but you can t convert a string to a char if it s more than one character long. You can t convert a char to a double, no matter what you do, because the two types are incompatible. This means that if your code requires a conversion, you should include some error-checking code to ensure that your program doesn t crash if the user enters bad data for example, if the user enters Q in the age-checking code we just showed you. We ll get to that in 16; for the time being, we ll assume that you have perfect users who always do just what they re told, and never enter bad data. (When you re done with them, can you send them over our way We d love to meet them.)
Copyright © OnBarcode.com . All rights reserved.