ArticleDirectory
Indexer (C # programming guide)
Indexer (C # programming guide)
Visual Studio 2005
Other Versions
Visual Studio 2010
Visual Studio 2008
The indexer allows instances of classes or structures to be indexed in the same way as arrays. The indexer is similar to an attribute, but its access
Public stringShow () + { A return "name"+ Name +"account is"+Kemu; the } + } - Public classIndexer $ { $ Publicanimal[] ANI; - PublicIndexer (intcount) - { the if(Count 0) -Console.WriteLine ("The length is not legal");WuyiANI =NewAnimal[count]; the } - Wu PublicAnimal This[intIndex] - { About Get $ { - if(Index >ANI. Length) -
The session of nhib.pdf. the find method may return a collection of object arrays, such as find ("select customer. ID, customer. name from customer "), which returns an arraylist consisting of object [2. I don't know how to bind it to the DataGrid. Later I found databinder. eval can use the expression "[XXX]" to access the indexer. so
The customer ID and name can be obtained respectively.
Hashtable indexer Definition:
// Summary: // Gets or sets the value associated with the specified key. // // Parameters: // Key: // The Key whose value to get or set. // // Returns: // The value associated with the specified key. If the specified key is not // Found, attempting to get it returns NULL, and attempting to set it creates // A new element us
The current Silverlight client binding supports the indexing method. For example, the VM has attributes:Public dictionary In the backend CS, we want to access the value of a key by keyvalues ["XXXX"], where XXXX is the key. in XAML, we can access the following:TEXT = "{bindings Path = keyvalues [xxxx]}"As long as the indexer itself supports get, set can also implement bidirectional binding. However, there is a defect in this two-way approach, that is,
The index function is a further extension of attributes. It can control the reading and writing of multiple variables in an array. The popular point is that you can beat a cow in the mountains. You can also beat a cow directly, but it may be difficult to control the intensity. The indexer achieves this effect. Let's take a look at the implementation below.Code:
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.Cod
First, indexerIndexers are similar to properties, except that their get accessors take parameters. To declare an indexer on a class or struct, use the This keyword.Example:Indexer Sample code///The class that stores the day of the week. Declares a get accessor that accepts a string and returns the corresponding integerpublic class Week{Public string[] weeks = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
When a class contains arrays or set members, you can use the indexer to greatly simplify access to arrays or set members.
The usage is as follows:
[Modifier] Data TypeThis[Index]{Get{//Obtain the attributeCode}Set{//Code for setting attributes}}//Modifiers include public, protected, Private, internal, new, virtual, sealed, override, abstract, and extern.//The data type is the type of the array or set element to be accessed.
For example, the foll
Garmmar:[Access modifier] Data type this[parameter list]{Get{Gets the contents of the indexer}Set{Set the contents of the indexer}}Eg:1"font-size:14px;">usingSystem; 2 usingSystem.Collections.Generic; 3 usingSystem.Text; 4 5 namespaceindexerusing6 { 7 classPhoto8 { 9 Ten Private stringname; One A Public stringName -
Indexer is a new addition in C #, some friends may be confused, some of the things that have been done recently
Often use index, conveniently write a simple example for everyone to see if there are any questions to ask!
This example contains three classes: DataRow, DataItem, Dataitemcollection.
The indexer is used in dataitemcollection.
Using System;
Using System.Collections;
public static void Main (stri
Related topics: vertex arrays, display lists, pixel buffer objects
Download: Vbo.zip, Vbosimple.zip
Create VBO to draw VBO Update Vbo ExampleThe Gl_arb_vertex_buffer_object extension improves OpenGL performance by providing the advantages of vertex arrays and display lists and avoiding their shortcomings. The vertex buffer object (
Use of Indexer
Requirement: the student class array is used to store the student class. If you want to access this array, you need to use an index. In this way, we must be very clear about the index of the elements in the array, which is inconvenient to use, because it is easy for us to remember the Student name, we want to access this array through the student name. So:
Solution:1. Change the array attribute student [] in the original class to th
From: http://www.cnblogs.com/csharp4/archive/2010/06/03/1750938.html
Why do we need something like indexer?
When we want to define a custom collection type, such as EmployeeCollection and ManagerCollection. because of the functional requirements, we use a generic collection class for storage in such a class. We also need to encapsulate some other necessary related methods in the class, for example, how to calculate the salary and how many working days
The indexer allows you to easily use the Array (or set) members in the class:
Using system; Class myclass {private float [] FS = new float [3] {1.1f, 2.2f, 3.3f};/* attribute */Public int length {get {return FS. length ;}set {FS = new float [value] ;}/ * indexer */public float this [int N] {get {return FS [N];} set {FS [N] = value ;}} class program {static void main () {myclass OBJ = new myclass (); Fo
Program//Indexedproperty.cs
Using System;
public class Document
{
Type allowing the document to is viewed like an array of words:
public class Wordcollection
{
ReadOnly document document; The containing document
Internal Wordcollection (Document D)
{
Document = D;
}
Helper Function--Search character array "text", starting at
Character "Begin" for word number "wordCount." Returns false
If there are less than wordCount words. Sets "Start" and
Length "to the position and length of the word withi
C # Index Structure
...{Get...{// Get codes goes here}Set...{// Set codes goes here}}
Note:
Modifier: modifier, such as private, public, protected or internal
This: in C #, this is a special keyword that indicates the current instance of the referenced class. It indicates the index of the current class.
Argument list: the parameters of the indexer.
Example:
Class SampleCollection {Private T [] arr = new T [100];Public T this [int I]{Get{Return arr [I
Due to inertia, indexer is often used as an entry to feedback results by number.
But like where in SQL, we can actually do a lot.
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Using
System;
Using
System. Collections. Generic;
Using
System. text; Namespace Leleapplication2{ Class C{ Float [] Temps = New Float [ 10 ] { 56.2f , 56.7f , 56.5f , 56.9f , 58.8f , 61.3
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.