What purpose do indexers have?
My script is in c#. There is an error that the left-hand side of an assignment must be a variable, property, or an indexer. I'm not sure what function an indexer plays scripting, all I know is that it's related to arrays in a form, that it declares a shared data entry, but I'm not sure what would fall under it. Help?
Could you copy and paste the line that the error is on? It sounds like you just put your variable on the right ins$$anonymous$$d of the left of the equation.
Answer by WolfpackPancake · Dec 12, 2015 at 06:04 AM
Searched Google And Found This
"C# introduces a new concept known as Indexers which are used for treating an object as an array. The indexers are usually known as smart arrays in C# community. Defining a C# indexer is much like defining properties. We can say that an indexer is a member that enables an object to be indexed in the same way as an array. this [argument list] { get { // Get codes goes here } set { // Set codes goes here } }
Where the modifier can be private, public, protected or internal. The return type can be any valid C# types. The 'this' is a special keyword in C# to indicate the object of the current class. The formal-argument-list specifies the parameters of the indexer. The formal parameter list of an indexer corresponds to that of a method, except that at least one parameter must be specified, and that the ref and out parameter modifiers are not permitted. Remember that indexers in C# must have at least one parameter. Other wise the compiler will generate a compilation error.
The following program shows a C# indexer in action // C#: INDEXER
using System; using System.Collections;
class MyClass { private string []data = new string[5]; public string this [int index] { get { return data[index]; } set { data[index] = value; } } }
class MyClient { public static void Main() { MyClass mc = new MyClass(); mc[0] = "Rajesh"; mc[1] = "A3-126"; mc[2] = "Snehadara"; mc[3] = "Irla"; mc[4] = "Mumbai"; Console.WriteLine("{0},{1},{2},{3},{4}",mc[0],mc[1],mc[2],mc[3],mc[4]); } }"
Your answer
Follow this Question
Related Questions
Get the index of the currently selected HandleUtility.FreeMoveHandle in Scene View 0 Answers
IndexOutOfRangeExeption! This doesent even affect my gameplay, it just is there to be annoying! 1 Answer
Unknown Argument Out of Range Index Error On Card Game 1 Answer
[help] Array index is out of range 0 Answers