- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Collections and Generics in C#
4 Creating QR-Code In C#.NET Using Barcode printer for Visual Studio .NET Control to generate, create QR Code 2d barcode image in VS .NET applications. www.OnBarcode.comDecoding QR In C#.NET Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET applications. www.OnBarcode.comCollections and Generics
Printing Bar Code In C#.NET Using Barcode creation for VS .NET Control to generate, create bar code image in VS .NET applications. www.OnBarcode.comBar Code Decoder In Visual C#.NET Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comFor Each i as KeyValuePair(Of String, Integer) in sortList Console.WriteLine(i) Next // C# SortedList<string, int> sortList = new SortedList<string, int>(); sortList["One"] = 1; sortList["Two"] = 2; sortList["Three"] = 3; foreach (KeyValuePair<string, int> i in sortList) { Console.WriteLine(i); } Making QR Code In .NET Framework Using Barcode printer for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications. www.OnBarcode.comEncoding QR Code In VS .NET Using Barcode drawer for VS .NET Control to generate, create QR Code JIS X 0510 image in VS .NET applications. www.OnBarcode.comThe use of the SortedDictionary is identical. To use a SortedDictionary, follow these steps: 1. Create an instance of SortedDictionary, specifying the key and value generic type parameters. 2. You can use indexer syntax to add or retrieve items in the SortedDictionary, but they must match the types specified in the generic type parameters of the SortedDictionary. 3. Create a foreach structure, specifying a generic KeyValuePair class as the type of object to be returned in each iteration. The types specified in the KeyValuePair must match the types used in the original SortedDictionary. 4. Inside the foreach block, you can use the KeyValuePair to retrieve the keys and values with properties called Key and Value, respectively. This example stores integers as the keys and strings as the values of the SortedDictionary: QR Code 2d Barcode Encoder In Visual Basic .NET Using Barcode maker for .NET Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications. www.OnBarcode.comDataMatrix Creation In Visual C# Using Barcode generator for .NET Control to generate, create DataMatrix image in VS .NET applications. www.OnBarcode.com' VB Dim sortedDict as new SortedDictionary(Of String, Integer)() sortedDict("One") = 1 sortedDict("Two") = 2 sortedDict("Three") = 3 For Each KeyValuePair(Of string, int) i in sortedDict Console.WriteLine(i) Next // C# SortedDictionary<string, int> sortedDict = new SortedDictionary<string, int>(); sortedDict["One"] = 1; sortedDict["Two"] = 2; sortedDict["Three"] = 3; GS1 - 12 Drawer In Visual C#.NET Using Barcode printer for .NET Control to generate, create UPC Symbol image in .NET applications. www.OnBarcode.comMake USS Code 128 In C#.NET Using Barcode creator for .NET framework Control to generate, create Code 128A image in Visual Studio .NET applications. www.OnBarcode.comLesson 5: Generic Collections
Draw Barcode In C#.NET Using Barcode creator for .NET Control to generate, create barcode image in Visual Studio .NET applications. www.OnBarcode.comPrinting 2 Of 7 Code In C#.NET Using Barcode maker for .NET framework Control to generate, create ANSI/AIM Codabar image in .NET applications. www.OnBarcode.comforeach (KeyValuePair<string, int> i in sortedDict) { Console.WriteLine(i); } UPC - 13 Encoder In None Using Barcode generator for Excel Control to generate, create EAN 13 image in Excel applications. www.OnBarcode.comMaking Barcode In Visual Studio .NET Using Barcode generator for ASP.NET Control to generate, create barcode image in ASP.NET applications. www.OnBarcode.comGeneric LinkedList Class
QR Decoder In Visual C#.NET Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comGS1-128 Generation In None Using Barcode creation for Office Word Control to generate, create UCC - 12 image in Word applications. www.OnBarcode.comThe generic LinkedList class is a type of collection that is new to .NET, though the concept is well worn and tested. In fact, I remember writing a LinkedList in college. The idea behind a linked list is a set of items that are linked to each other. From each item, you can navigate to the next or previous item without having to have access to the collection itself. This is very useful when you are passing objects around that need to know about their siblings. Table 4-21 and Table 4-22 show the interface to the generic LinkedList class: Code 128 Code Set B Printer In Objective-C Using Barcode printer for iPad Control to generate, create ANSI/AIM Code 128 image in iPad applications. www.OnBarcode.comGS1 - 12 Generation In None Using Barcode maker for Word Control to generate, create UPC-A Supplement 2 image in Microsoft Word applications. www.OnBarcode.comTable 4-21 LinkedList Properties
Make QR Code In None Using Barcode creator for Software Control to generate, create Denso QR Bar Code image in Software applications. www.OnBarcode.comGS1 128 Printer In None Using Barcode printer for Font Control to generate, create UCC.EAN - 128 image in Font applications. www.OnBarcode.comName Count First Last
Description Gets the number of nodes in LinkedList Gets the first node in LinkedList Gets the last node in LinkedList Table 4-22 LinkedList Methods
Name AddAfter AddBefore AddFirst AddLast Clear Contains CopyTo Find FindLast
Description Adds a new node after an existing node in LinkedList Adds a new node before an existing node in LinkedList Adds a new node at the beginning of LinkedList Adds a new node at the end of LinkedList Removes all nodes from LinkedList Tests to see whether a value is contained within LinkedList Copies the entire LinkedList to an Array Locates the first node containing the specified value Locates the last node containing the specified value 4
Collections and Generics
Table 4-22 LinkedList Methods
Name Remove RemoveFirst RemoveLast
Description Removes the first occurrence of a value or node from LinkedList Removes the first item from LinkedList Removes the last item from LinkedList A LinkedList contains a collection of LinkedListNode objects. When working with a LinkedList, you will be primarily getting and walking down the nodes. The properties of the generic LinkedListNode class are detailed in Table 4-23. Table 4-23 LinkedListNode Properties
Name List Next Previous Value
Description Gets the LinkedList that the node belongs to Gets the next node in the LinkedList Gets the previous node in the LinkedList Gets the value contained in the node. One peculiarity of the generic LinkedList class is that the implementation of the enumerator (ILinkedListEnumerator) allows for enumeration of the values of the list without using LinkedListNode objects. This behavior is unlike the generic Dictionary type, where the enumerator returns a generic NameValuePair object. The difference exists because LinkedListNode objects can be used to walk the list of items, but only one piece of data is in each node. Therefore, there is no need to return the nodes during enumeration. To use a LinkedList, you can create an instance of the LinkedList class, specifying the type to be stored as values in the list, then you can perform any of the following actions: You can use the AddFirst and AddLast methods to add items to the beginning and end of the list, respectively. The AddFirst and AddLast methods return a LinkedListNode if you are simply specifying the value in these methods. You can also use the AddBefore and AddAfter methods to add values in the middle of the list. To use these methods, you need to have access to a LinkedListNode at which you want to add values before or after.
|
|