[Help] Get the instance name of an object

Hey all,

So I am taken an evening course in C# and we got an assignement where we have to make a collectionclass of figures containing balls or cubes and one of the functions has to return the instancename of the heaviest object but I can't seem to get it to return me the instance name.

For example ball1 is 150grams, the heaviest, I want my program to return "ball1".

This is the code:

…. public string GetNaamZwaarste() { int zwaarste = 0; for (int i = 0; i < Count; i++) { int gewicht; gewicht = this[i].GetGewicht(); if ( gewicht > zwaarste) { zwaarste = i; } } return Convert.ToString(this[zwaarste]); } …. // Naam van de zwaarste figuur Console.WriteLine(figuren.GetNaamZwaarste());

Thanks in advance.

by kennyphilipss via /r/csharp

Leave a Reply