Function explanation c#

Hello all,

I am using a class that i downloaded from: http://www.codeproject.com/KB/recipes/K-Mean_Clustering.aspx

And in the class Kmeans. They say that this function:

/// <summary>
            /// Returns the one dimensional array data located at the index
            /// </summary>
            public virtual double [] this[int Index]
            {
                  get
                  {
                        //return the Neuron at IList[Index]
                        return (double[])this.List[Index];      
                  }    
            }
I don't understand how to get the list. it's the first time that i see this in c# i am really new. Thank you.
dadadudeAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
In looking at that definition, what I see is the class KMeans is a class which implements IEnumerable, meaning it can be indexed. Think of it basically as an array itself. This "array" holds lists of doubles in each of its slots. When you have an instance of this class:

    KMeans instance = new KMeans();

you can treat it like an array and index it:

    double[] aList = instance[0];
0
 
käµfm³d 👽Commented:
Actually, I made an assumption that it implements IEnumerable--that may or may not be accurate. The concept of treating it like an array still applies though.
0
 
lalitgadaCommented:
crate an object of Ilist
and return that object.
0
 
dadadudeAuthor Commented:
yes Thank you, Kaufmed. Actually i managed to understand it. thank you for your explanation. It was just a list of double. But the way that it is written is new for me.

Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.