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}