C, the role and usage of indexers

Updated on healthy 2024-02-09
4 answers
  1. Anonymous users2024-02-05

    Indexer definitions are similar to properties but their functionality is not the same as properties Indexers provide a special way to write get and set accessors Properties can access an object's data in the same way as a field Indexers allow users to access class members in the same way as arrays The syntax for defining an indexer is as follows:

    Access the modifier type name this [type name parameter name].

    getset

    The indexer doesn't have a name like properties and methods, the keyword this clearly expresses the characteristics of the indexer's reference object, and like the property, the value keyword has a meaning for passing arguments in the block after the set.

    As with the method, the indexer has a new public protected internal private and an inheritance behavior modifier virtual sealed override abstract and an external indexer These behaviors are no different from the methods The only difference is that the indexer cannot be static, which is easy to understand in the semantics of object references It is worth noting that in override When implementing an indexer, base[e] should be used to access the indexer of the parent class.

    As with the property implementation, the data type of the indexer is the return type of the get block and the type of the value keyword in the set block.

    The indexer's parameter list is also worth noting: The indexer's feature makes it necessary for the indexer to have at least one parameter, which is in parentheses after the this keyword, and the indexer's parameters can only be of the value transfer type, and cannot be ref (reference) and out (output) modifications, and the data type of the parameter can be any data type in c c Polymorphism of the indexer is performed according to different parameter signatures, and all parameters in parentheses can be referenced under get and set The value keyword can only be used as a passing parameter under set.

    Indexers allow instances of a class or structure to be indexed in the same way as arrays Indexers are similar to properties except that their accessors take parameters.

    get accessor return value set accessor assignment value.

    The this keyword is used to define the index.

    The value keyword is used to define the value assigned by the set indexer.

    Indexers don't necessarily index based on integer values, you can specify the parameter type based on your programming requirements.

    Indexers can be overloaded.

    An indexer can have multiple parameters, such as when accessing a two-dimensional array.

    lishixinzhi/article/program/net/201311/12727

  2. Anonymous users2024-02-04

    Indexer: is a new type of class member introduced by C, a special class member that allows objects to be accessed in an array-like manner, making the program look more intuitive and easier to write.

    Indexers are different from attributes, but they differ in that the indexer's accessors take parameters.

    Once the indexer is defined, you can use operators to access the members of the class in the same way as arrays.

    Defining an indexer is somewhat similar to defining a property, and its general form is as follows:

    Modifier] data type this <[data type identifier]>set}

  3. Anonymous users2024-02-03

    Generally speaking, classes that implement indexers are collection classes or contain collection classes. The indexer allows you to easily reference the data in this collection.

    Indexers do not need to be declared and can be used directly on classes that declare indexers.

    The main difference between an indexer and an array is that.

    The index value of an indexer does not have to be an integer.

    The index value used to access an array must be of type an integer, but indexers can define other types of index values.

    Indexers allow overloading

    A class is not limited to defining only one indexer, as long as the indexer function signature is different, a class can have many indexers, and you can override its functionality.

    The indexer is not a variable.

    The difference between an index and an array is that an indexer doesn't directly correspond to a reference data store, whereas an array does. Indexers have a get accessor and a set accessor, which are used to indicate the ** that needs to be executed when the indexer element is to be read or written.

    In your case, myclass has an int array or collection inside it, and the index you're using actually goes to reference the inner collection class.

  4. Anonymous users2024-02-02

    An indexer is a property method of class or struct. Indexers allow you to use the data inside an instance like an array.

    The following class defines an indexer, the public class, myclass

    Indexer indexer

    public int this[int index]set}

    Instantiate myclass

    myclass my=new myclass();

    Assign a value through an indexer.

    my[0]=123;

    my[1]=456;

    my[2]=789

    From the class definition, it can be seen that 123 is placed in innerdata[0] inside the instance, and 456 is stored in innerdata[1] ......And so on.

Related questions
27 answers2024-02-09

There are two kinds of self-increment and self-reduction, one is the forward fall (++i,--i), and one suffix (i++, i--) There is a big difference between the two, and the prefix self-increment and self-decrease is to run itself first, and then run others. The suffix is self-incrementing and self-decreasing, which is to run the other first in the run itself. >>>More

4 answers2024-02-09

When two different types of networks are connected to each other, a router must be used. For example, LAN A is a token ring network, and LAN B is an Ethernet, so you can use a router to connect the two LANs together. >>>More

11 answers2024-02-09

It's textbox, right? textbook?

double somedouble; >>>More

7 answers2024-02-09

struts do request processing and **, hibernate does data persistence, spring provides control reversal and AOP services, generally speaking, novices will take some time to understand the role of spring, in layman's terms, it can help you new the class you need, it can be a singleton or a prototype, you can also help you do some interception such as permission interception, internationalization interception, etc., and can also help you manage hibernate such as transaction delivery.

18 answers2024-02-09

It plays the role of filtering, because the AC after rectification is pulsating DC, and the charge-discharge effect of the capacitor is required to change the pulsating DC into a stable DC.