Indexers [modified]
-
I just discovered indexers today (using Reflector and a bit of googling) and found that they solve some problems I had been having with a class. Having just found them, my initial thoughts were "excellent! this solves all of the problems of the world" So my question is this: Are indexers common knowledge (and I have been living under a rock until today) OR Are indexers obscure things only usually found in the System.whatever? (The reason I ask is that the project I'm working on seems like a candidate for an article, but when I write it I dont want to patronise people by telling them all about this magic syntax I discovered if everybody already knows) Thanks, Chris [Edit: After a couple of replies it seems that it is common knowledge, however I suspect that people have come from a C++ background - any VB background people care to chip in?]
modified on Monday, August 18, 2008 11:17 AM
-
I just discovered indexers today (using Reflector and a bit of googling) and found that they solve some problems I had been having with a class. Having just found them, my initial thoughts were "excellent! this solves all of the problems of the world" So my question is this: Are indexers common knowledge (and I have been living under a rock until today) OR Are indexers obscure things only usually found in the System.whatever? (The reason I ask is that the project I'm working on seems like a candidate for an article, but when I write it I dont want to patronise people by telling them all about this magic syntax I discovered if everybody already knows) Thanks, Chris [Edit: After a couple of replies it seems that it is common knowledge, however I suspect that people have come from a C++ background - any VB background people care to chip in?]
modified on Monday, August 18, 2008 11:17 AM
-
c2423 wrote:
Are indexers common knowledge
Yes
c2423 wrote:
(and I have been living under a rock until today)
I don't know. :)
led mike
-
I just discovered indexers today (using Reflector and a bit of googling) and found that they solve some problems I had been having with a class. Having just found them, my initial thoughts were "excellent! this solves all of the problems of the world" So my question is this: Are indexers common knowledge (and I have been living under a rock until today) OR Are indexers obscure things only usually found in the System.whatever? (The reason I ask is that the project I'm working on seems like a candidate for an article, but when I write it I dont want to patronise people by telling them all about this magic syntax I discovered if everybody already knows) Thanks, Chris [Edit: After a couple of replies it seems that it is common knowledge, however I suspect that people have come from a C++ background - any VB background people care to chip in?]
modified on Monday, August 18, 2008 11:17 AM
-
Indexers are nice and commonly used in the .NET framework. If you think they would make sense in your project and simplify the usage of it, then go for indexers. regards
Yes, they simplify my project (in one place I even save an *entire line* of code :laugh: ) And I know that the framework contains them (for example when reading a SqlDataReader's values) However, my question was more along the lines of "do people generally know of their existance?" Anyway, thanks for your input - its good to know that its not an alien concept for people! Thanks, Chris
-
Yes, they simplify my project (in one place I even save an *entire line* of code :laugh: ) And I know that the framework contains them (for example when reading a SqlDataReader's values) However, my question was more along the lines of "do people generally know of their existance?" Anyway, thanks for your input - its good to know that its not an alien concept for people! Thanks, Chris
c2423 wrote:
However, my question was more along the lines of "do people generally know of their existance?"
I think most people use them intuitively when accessing chars in strings, items in lists, values by key in dictionaries and lots of other stuff. Whenever the user knows that there's more data inside a class they either look for a
GetXXX
-Method or go for indexers without actually knowing that they just use "indexers". regards -
c2423 wrote:
However, my question was more along the lines of "do people generally know of their existance?"
I think most people use them intuitively when accessing chars in strings, items in lists, values by key in dictionaries and lots of other stuff. Whenever the user knows that there's more data inside a class they either look for a
GetXXX
-Method or go for indexers without actually knowing that they just use "indexers". regardsPerhaps I wasn't being clear in my posts:
Greeeg wrote:
I think most people use them intuitively
Which is why I want to use them for my class :) However there is a difference between understanding:
string x = "hello world";
char y = x[0];And being able to write:
this[int indexno]
{
get { return something; }
}What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.
-
Perhaps I wasn't being clear in my posts:
Greeeg wrote:
I think most people use them intuitively
Which is why I want to use them for my class :) However there is a difference between understanding:
string x = "hello world";
char y = x[0];And being able to write:
this[int indexno]
{
get { return something; }
}What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.
c2423 wrote:
What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.
This totally depends on the experience of the developer :confused: Experienced developers who have been programming with C# for quite a while will definitely know of their existence, while newcomers to C# probably miss them and go the
GetXXX
-way. -
Thanks for your input! In conclusion I must just not have been paying attention to the C# books I glossed over... Chris
c2423 wrote:
Thanks for your input!
No problem. Man I sure missed an opportunity in replying to your other question!
c2423 wrote:
(and I have been living under a rock until today)
I don't know, what's your address? I can look it up on Google Street View and tell you! :-D
led mike
-
c2423 wrote:
What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.
This totally depends on the experience of the developer :confused: Experienced developers who have been programming with C# for quite a while will definitely know of their existence, while newcomers to C# probably miss them and go the
GetXXX
-way.When I first read "Indexer" I didn't know what you mean, but after seeing the example I realized you were talking about the [] operator. I think that almost every C++ developer might know that, as you can overload a lot of operators in C++ and it's something very useful. BTW, the GetXXX method, is a method that connects to the internet and downloads adult contents from a porn site. :laugh:
rotter
-
c2423 wrote:
What I wanted to know was are people familiar with how to add this functionality to a class, rather then can people use a class which already has this functionality.
This totally depends on the experience of the developer :confused: Experienced developers who have been programming with C# for quite a while will definitely know of their existence, while newcomers to C# probably miss them and go the
GetXXX
-way. -
When I first read "Indexer" I didn't know what you mean, but after seeing the example I realized you were talking about the [] operator. I think that almost every C++ developer might know that, as you can overload a lot of operators in C++ and it's something very useful. BTW, the GetXXX method, is a method that connects to the internet and downloads adult contents from a porn site. :laugh:
rotter