C # Programming weapon of the Five: Collection Object (Collections)

Source: Internet
Author: User

Remember the textbook: "If you need to use multiple objects of the same type, you can use collections and arrays." "Yes, nothing wrong. Just the size of the array is fixed. If the number of elements is dynamic, you should use the collection class. In the. NET framework, there are many collections, such as list<t> and ArrayList, which are the collection classes that are equivalent to arrays. There are other types of collections: queues, stacks, lists, and dictionaries. This article will not give a detailed description of these collection objects, but the common collection object to discuss.

One, array

In practical applications, arrays can be divided into: simple arrays, multidimensional arrays, jagged arrays, array arrays. Use the most simple arrays and multidimensional arrays that should be counted, here I take a simple array as an example to introduce the simple use of the array, the other knowledge points please refer to the relevant information and books.

Let's say we're going to define a simple array of integers, so how do we define that?

1 class Program
 2 {
 3     static void Main (string[] args)
 4     {
 5         int[] users = new int[5];
 6         users[0] = ten;
 7         users[1] =;
 8         //
 9     }
10}

is the above defined and used? I think a friend who has learned a little bit of programming can give a positive answer. I don't want to explain too much about this. See figure below:

Here we are using the base type (int) type to define the array, in the use of development we will also use a custom type array, I will briefly say this knowledge. To define a custom type array, you should first have a custom type, which, of course, can block other related attributes. OK, the following code snippet:

 1///<summary>
 2///Custom type User, internally encapsulates a property name.
 3///</summary>
 4 public class User
 5 {
 6     private string name;
 7 public     string Name
 8     {
 9 get         {return Name;}
Ten         set {name = value;}
One     }
12}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.