private List<string> _S3 = new List<string>();
public string S3[int index]
{
get
{
return _S3[index];
}
}
Only problem is I get 13 errors. I want to call string temp = S3[0]; and get the string value from the list with the particular index.
You can’t do that in C# – you can’t have named indexers like that in C#. You can either have a named property, with no parameters, or you can have an indexer with parameters but no name.
Of course you can have a property with a name which returns a value with an indexer. For example, for a read-only view, you could use:
That way the underlying collection is still read-only from the public point of view, but you can access an element using:
You could create a new
ReadOnlyCollection<string>on each access toS3, but that seems a little pointless.