sammy tammy
sammy tammy

Reputation: 3

What is the name of this c# shorthand?

I have seen the below code. I understand what it's doing. It gets a list of enum and then matches it with value passed and returns the matched one. What is this shorthand called? Is there a link a to more advanced short hands like this?

string a = null;
a = getListOfEnums()["matching value"];

Edit It does not need to be an enum. It can be a dictionary object (key value pair) too.

Upvotes: 0

Views: 69

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125630

Are you sure about the code? In current form the only way it may work is that getListOfEnums() returns a delegate that takes a string and returns a string. That wouldn't match name of the method, so I don't think that's the case.

What I think you're talking about is indexer:

string a = null;
a = getListOfEnums()["matching value"];

Upvotes: 1

Related Questions