qr code c# mvc Lab: Working with Reference Types in C#

Generation QR Code in C# Lab: Working with Reference Types

Lab: Working with Reference Types
Printing QR Code 2d Barcode In Visual C#.NET
Using Barcode generation for .NET Control to generate, create QR Code image in .NET applications.
www.OnBarcode.com
QR Code 2d Barcode Reader In Visual C#.NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
The following exercises reinforce knowledge of reference types, strings, and exceptions. If you encounter a problem completing an exercise, the completed projects are available on the companion CD in the Code folder.
Barcode Generator In Visual C#
Using Barcode creation for Visual Studio .NET Control to generate, create bar code image in Visual Studio .NET applications.
www.OnBarcode.com
Bar Code Decoder In C#
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
1
Painting QR In .NET Framework
Using Barcode generation for ASP.NET Control to generate, create QR Code ISO/IEC18004 image in ASP.NET applications.
www.OnBarcode.com
QR Drawer In .NET
Using Barcode generator for .NET framework Control to generate, create QR Code image in Visual Studio .NET applications.
www.OnBarcode.com
Framework Fundamentals
Painting QR In VB.NET
Using Barcode maker for .NET Control to generate, create QR Code ISO/IEC18004 image in .NET applications.
www.OnBarcode.com
European Article Number 13 Generation In Visual C#
Using Barcode generation for Visual Studio .NET Control to generate, create EAN13 image in VS .NET applications.
www.OnBarcode.com
Exercise 1: Identify Types as Value or Reference
Create UPC-A Supplement 5 In Visual C#.NET
Using Barcode creation for .NET Control to generate, create GTIN - 12 image in .NET applications.
www.OnBarcode.com
Making Barcode In C#
Using Barcode generator for .NET framework Control to generate, create bar code image in Visual Studio .NET applications.
www.OnBarcode.com
In this exercise, you will write a console application that displays whether objects are value or reference types. 1. Using Visual Studio, create a new console application project. Name the project List-Value-Types. 2. Create instances of the following classes:
Draw EAN / UCC - 14 In Visual C#.NET
Using Barcode maker for VS .NET Control to generate, create EAN / UCC - 14 image in VS .NET applications.
www.OnBarcode.com
4-State Customer Barcode Drawer In C#
Using Barcode maker for .NET framework Control to generate, create 4-State Customer Barcode image in .NET applications.
www.OnBarcode.com
SByte Byte Int16 Int32 Int64 String Exception
GS1-128 Generation In .NET
Using Barcode creator for Reporting Service Control to generate, create EAN / UCC - 13 image in Reporting Service applications.
www.OnBarcode.com
Recognizing Code 3/9 In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
The following code demonstrates this:
Generate Barcode In Java
Using Barcode creation for Android Control to generate, create bar code image in Android applications.
www.OnBarcode.com
Data Matrix ECC200 Scanner In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
' VB Dim a As SByte = 0 Dim b As Byte = 0 Dim c As Int16 = 0 Dim d As Int32 = 0 Dim e As Int64 = 0 Dim s As String = "" Dim ex As Exception = New Exception // C# SByte a = 0; Byte b = 0; Int16 c = 0; Int32 d = 0; Int64 e = 0; string s = ""; Exception ex = new Exception();
Data Matrix ECC200 Creation In None
Using Barcode generator for Microsoft Word Control to generate, create Data Matrix image in Office Word applications.
www.OnBarcode.com
Bar Code Recognizer In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
www.OnBarcode.com
3. Add each of the instances to a new object array, as the following code demonstrates:
QR Code ISO/IEC18004 Generation In VB.NET
Using Barcode creation for VS .NET Control to generate, create QR Code 2d barcode image in .NET framework applications.
www.OnBarcode.com
Paint PDF 417 In VB.NET
Using Barcode maker for .NET framework Control to generate, create PDF417 image in VS .NET applications.
www.OnBarcode.com
' VB Dim types As Object() = {a, b, c, d, e, s, ex} // C# object[] types = { a, b, c, d, e, s, ex };
Lesson 2: Using Common Reference Types
4. Within a foreach loop, check the object.GetType().IsValueType property to determine whether the type is a value type. Display each type name and whether it is a value type or a reference type, as the following code demonstrates:
' VB For Each o As Object In types Dim type As String If o.GetType.IsValueType Then type = "Value type" Else type = "Reference Type" End If Console.WriteLine("{0}: {1}", o.GetType, type) Next // C# foreach ( object o in types ) { string type; if (o.GetType().IsValueType) type = "Value type"; else type = "Reference Type"; Console.WriteLine("{0}: {1}", o.GetType(), type ); }
5. Run the console application, and verify that each type matches your understanding.
Exercise 2: Work with Strings and Arrays
In this exercise, you will write a function to sort a string. 1. Using Visual Studio, create a new console application project. Name the project SortString. 2. Define a string. Then use the String.Split method to separate the string into an array of words. The following code demonstrates this:
' VB Dim s As String = "Microsoft .NET Framework 2.0 Application Development Foundation" Dim sa As String() = s.Split(" ") // C# string s = "Microsoft .NET Framework 2.0 Application Development Foundation"; string[] sa = s.Split(' ');
1
Framework Fundamentals
3. Call the Array.Sort method to sort the array of words, as the following code demonstrates:
' VB Array.Sort(sa) // C# Array.Sort(sa);
4. Call the String.Join method to convert the array of words back into a single string, and then write the string to the console. The following code sample demonstrates this:
' VB s = String.Join(" ", sa) Console.WriteLine(s) // C# s = string.Join(" ", sa); Console.WriteLine(s);
5. Run the console application, and verify that it works correctly.
Exercise 3: Work with Streams and Exceptions
Consider a scenario in which a coworker wrote a simple Windows Forms application to view text files. However, users complain that it is very temperamental. If the user mistypes the filename or if the file is not available for any reason, the application fails with an unhandled exception error. You must add exception handling to the application to display friendly error messages to users if a file is not available. 1. Copy the 01\Lesson2-ViewFile folder from the companion CD to your hard disk, and open either the C# version or the Visual Basic .NET version of the ViewFile project. 2. Exceptions occur when users attempt to view a file. Therefore, edit the code that runs for the showButton.Click event. Add code to catch any type of exception that occurs, and display the error in a dialog box to the user. If an exception occurs after the TextReader object is initialized, you should close it whether or not an exception occurs. You will need two nested Try blocks: one to catch exceptions during the TextReader initialization, and a second one to catch exceptions when the file is read. The following code sample demonstrates this:
' VB Try Dim tr As TextReader = New StreamReader(locationTextBox.Text) Try displayTextBox.Text = tr.ReadToEnd
Copyright © OnBarcode.com . All rights reserved.