indexer

Item property in c#

安稳与你 提交于 2021-02-19 03:21:01
问题 Is item property in c# is always used like indexer in c#? Let me explain with an example. ArrayList is having many properties like count,capacity, and one of them is Item.Item Property unlike count and capacity which are accessed by putting dot after name of ArrayList ,is not used by keyword Item but directly by Indexer. e.g. ArrayList MyList = new ArrayList(); MyList.add(100); MyList[0] = 200; Like in above e.g. uses the Item keyword to define the indexers instead of implementing the Item

Item property in c#

◇◆丶佛笑我妖孽 提交于 2021-02-19 03:20:18
问题 Is item property in c# is always used like indexer in c#? Let me explain with an example. ArrayList is having many properties like count,capacity, and one of them is Item.Item Property unlike count and capacity which are accessed by putting dot after name of ArrayList ,is not used by keyword Item but directly by Indexer. e.g. ArrayList MyList = new ArrayList(); MyList.add(100); MyList[0] = 200; Like in above e.g. uses the Item keyword to define the indexers instead of implementing the Item

Indexer named “Item” required by interface but not possible to implement?

心已入冬 提交于 2021-02-19 02:37:20
问题 I'm trying to implement an interface of a class in the ESPRIT api that requires an indexer named "Item." (I'm guessing the interface came from VB.NET but I don't have the source.) Obviously the "Item[index]" indexer is auto-generated by the compiler by default but I'm getting the following errors: I realize [System.Runtime.CompilerServices.IndexerName("Item")] is redundant; it's simply there to demonstrate explicitly that Item is generated and the error remains. Attempting to implement public

How to declare the default indexed property in C++/CLI interface

浪子不回头ぞ 提交于 2021-01-27 20:31:01
问题 how is it possible to declare the default indexed property in an C++/CLI - Interface. (Please excuse the repeating, full qualified notation with namespaces because I'm just learning C++/CLI and want to be sure that no acciential mixup of language primitives between C++ and C# happens) Code is public interface class ITestWithIndexer { property System::String ^ default[System::Int32]; } Compiler always throws "error C3289: 'default' a trivial property cannot be indexed". Where is my error? PS:

How to write a class that (like array) can be indexed with `arr[key]`?

大兔子大兔子 提交于 2020-04-07 14:33:20
问题 Like we do Session.Add("LoginUserId", 123); and then we can access Session["LoginUserId"] , like an Array, how do we implement it? 回答1: You need an indexer: public Thing this[string index] { get { // get the item for that index. return YourGetItemMethod(index) } set { // set the item for this index. value will be of type Thing. YourAddItemMethod(index, value) } } This will let you use your class objects like an array: MyClass cl = new MyClass(); cl["hello"] = anotherObject; // etc. There's

How to write a class that (like array) can be indexed with `arr[key]`?

Deadly 提交于 2020-04-07 14:32:40
问题 Like we do Session.Add("LoginUserId", 123); and then we can access Session["LoginUserId"] , like an Array, how do we implement it? 回答1: You need an indexer: public Thing this[string index] { get { // get the item for that index. return YourGetItemMethod(index) } set { // set the item for this index. value will be of type Thing. YourAddItemMethod(index, value) } } This will let you use your class objects like an array: MyClass cl = new MyClass(); cl["hello"] = anotherObject; // etc. There's

Question about indexers and/or generics

风流意气都作罢 提交于 2020-01-04 01:58:11
问题 how is it possible to know whether an object implements an indexer?, I need to share a logic for a DataRow and a IDataReader, but they don't share any interface. I tried also with generics but don't know what restriction should I put on the where clause. public class Indexer { // myObject should be a DataRow or a IDataReader private object myObject; public object MyObject { get { return myObject; } set { myObject = value; } } // won't compile, myObject has no indexer public object this[int

Dynamic linq: Is there a way to access object data by index?

本秂侑毒 提交于 2019-12-30 10:29:45
问题 I need some in-memory filtering with Dynamic Linq. My objects have only a indexer: public object this[int index] { } The access to my data is like: object[0], object[1],... So my query is like this: // get FilterText from user at runtime // eg. filterText can be: [0] > 100 and [1] = "wpf" collection.AsQueryable().where(filterText); Is there any way to do this? 回答1: I have some news for you. It is actually possible... BUT! (Yes, there´s a but). I assume you are using the dynamic Linq library.