That is called the indexer. It is very similar to overloading operators for a class. Somewhere else in that class, or in one of that classes base classes, an indexer is defined.
Using this[] keyword to retrive a value from a class instant
Question
In the following example this[] is used within a class to obtain a value from somewhere from the class instant. Where is this value stored? Is it likely the [] operator being overloaded or is this just c# syntax I am unfamiliar with?
public class MyUserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
[DefaultSettingValue("white")]
public Color BackgroundColor
{
get
{
return ((Color)this["BackgroundColor"]);
}
set
{
this["BackgroundColor"] = (Color)value;
}
}
}
Solution
OTHER TIPS
It is the indexer syntax.
Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemble properties except that their accessors take parameters.
One of the classes that MyUserSettings
inherits from has implemented a string
indexer.
Yes it is an overloaded index operator.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow