một Indexer là gì? indexer An là một mảng thông minh trong cách chính xác giống như một tài sản là một lĩnh vực thông minh. Cú pháp mà bạn sử dụng cho một indexer là chính xác giống như cú pháp bạn sử dụng cho một mảng. Hãy làm việc thông qua một ví dụ. | What Is an Indexer An indexer is a smart array in exactly the same way that a property is a smart field. The syntax that you use for an indexer is exactly the same as the syntax you use for an array. Let s work through an example. First we ll examine a problem and see a weak solution that doesn t use indexers. Then we ll work through the same problem and look at a better solution that does use indexers. The problem concerns integers or more precisely the int type. An Example That Doesn t Use Indexers You normally use an int to hold an integer value. Internally an int stores its value as a sequence of 32 bits where each bit can be either 0 or 1. Most of the time you don t care about this internal binary representation you just use an int type as a bucket to hold an integer value. However sometimes programmers use the int type for other purposes some programs manipulate the individual bits within an int. If you are an old C programmer you should feel at home with what follows In other words occasionally a program might use an int because it holds 32 bits and not because it can represent an integer. NOTE Some older programs might use int types to try to save memory. A single int holds 32 bits each of which can be 1 or 0. In some cases programmers assigned 1 to indicate a value of true and 0 to indicate false and then employed an int as a set of Boolean values. For example the following expression uses the and bit manipulation operators to find out whether the bit at index 6 of the int called bits is set to 0 or to 1 bits 1 6 0 If the bit at index 6 is 0 this expression evaluates to false if the bit at index 6 is 1 this expression evaluates to true. This is a fairly complicated expression but it s trivial in comparison to the following expression that sets the bit at index 6 to 0 bits 1 6 It s also trivial compared with this expression that sets the bit at index 6 to 1 bits 1 6 The trouble with these examples is that although they work it s not clear why or how they .