Real world use cases for C# indexers? -
I have seen a lot of examples for C # indicators, but how to help me in real life situations.
I know that C # master if this is not a serious feature, then it would not have added me, but I would like to use a real world situation (not fu bar stuff) to use indexers I think.
Note: I know that one exists, but it does not help me
The way I see the indexers (right or wrong!), Something by the index By reaching it, it should be more efficient than reaching it in any other way, because in some way, in the shape or form, the index of the class I am using is any type of store index To reach the way, it helps in looking at values quickly.
The classic example is an array, when you use the element n of an array using the code [3], the compiler / interpreter knows which are the large (memory-wise) elements of the array And it can do offset from beginning to array, you can also {{=} (int i = 0; i & lt; myarray.length; i ++) {if (i = 3) for {. . Do stuff}} " (Not that you ever want!), Which will be less efficient, also shows how an array is a bad example.
Say that you have a collection category which stores, Umm, DDD, therefore:
Public class DVDCLANCTION {Private dictionary & lt; String, DVD & gt; Store = null; Private dictionary & lt; ProductId, string & gt; DvdsByProductId = Faucet; Public DVDCollection () {// receives DVD data from anywhere and stores it in "Store" by * TITLE * in / in a Lookup set of DVD ProductId and "dvdsbyProductid" store = new dictionary & lt; String, DVD & gt; (); DvdsByProductId = New Dictionary & lt; ProductId, string & gt; (); } // Get related DVD, using an index, product ID [ProductId index] by public DDV {var title = dvdsByProductId [index]; Return shop [title]; }}
Just my 2p, but, as I said, .. I always considered as the "indexor", which is a great way to get data from something is. / Em>
Comments
Post a Comment