| Start |
|---|
| Using collection initializers Some collection types can be initialized at the declaration time. For example, the following statement creates and initializes the Internally, the C# compiler actually converts this initialization to a series of calls to the Add method. Consequently, you can use this syntax only for collections that actually support the The For complex collections such as the The first item in each pair is the key, and the second is the value. |
Creating an initialized List with Custom Types Here we have a Class with no constructor with two properties: Here, we are creating several This allows us to initialize our List a little differently. What about a Class where one of the properties is a class itself? Notice we reverted the constructor on the Note that we can interchange our |
| Queue There is a collection in .Net used to manage values in a First, add the namespace: and use it: There is a non generic version of the type, which works with objects. The namespace is: Adn a code sample fo non generic queue: There is also a method called Peek() (opens new window) which returns the object at the beginning of the queue without removing it the elements. The output (without removing): |
| Stack There is a collection in .Net used to manage values in a First, add the namespace: and use it: There is a non generic version of the type, which works with objects. The namespace is: And a code sample of non generic stack: There is also a method called Peek() (opens new window) which returns the last element added but without removing it from the It is possible to iterate on the elements on the stack and it will respect the order of the stack (LIFO). The output (without removing): RemarksThere are several kinds of collection:
|
Read Article
https://develop.horje.com/learn/1434/reference