Aas Salamu Aalaikum
I’m facing a problem while using C#.NET class. I think my problem is very silly and most of the time I stuck in my programs for silly problems. (Most silly problems…!)
I create a class using C# and my problem is set the value in the class and getting the value from the class..!!! (I know its heard silly…!!) Whatsoever, my code isn’t working.
Here’s my class
using System;
using System.Collections;
namespace Proj_Puzzle_Game
{
/// <summary>
/// Summary description for CHighScore.
/// </summary>
public class CHighScore
{
public string[] Toplayers = new string[11]{ "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None" };
public int[] TopScore = new int [11]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public string singplay;
public int singscore;
int i, t;
string temp;
/* public class myReverserClass : IComparer
{
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
int IComparer.Compare( Object x, Object y )
{
return( (new CaseInsensitiveComparer()).Compare( y, x ) );
}
}
*/
public int SingleScore
{
get
{
return singscore;
}
set
{
singscore = value;
}
}
public string SinglePlayer
{
get
{
return singplay;
}
set
{
singplay = value;
}
}
public CHighScore()
{
//
// TODO: Add constructor logic here
//
//IComparer myComparer = new myReverserClass();
i=0;
while(i<11)
{
if(Toplayers[i]!= "None")//find a empty slot
i++;
else if(i==10)// while no empty slot found
{
Toplayers[i] = SinglePlayer;
TopScore[i] = SingleScore;
break;
}
else // insert into a empty slot
{
Toplayers[i] = SinglePlayer;
TopScore[i] = SingleScore;
break;
}
}
if(i==11)
i--;
//Insertion Sorting Algorithm
while(i>0)//according to previous position of i
{
if(TopScore[i]>TopScore[i-1])//if true lift it up
{
temp = Toplayers[i];
Toplayers[i] = Toplayers[i-1];
Toplayers[i-1] = temp;
t = TopScore[i];
TopScore[i] = TopScore[i-1];
TopScore[i-1] = t;
}
i--;
}
//Array.Sort(TopScore, Toplayers, myComparer);
}
// Sorts the entire Array using the default comparer.
}
}
And here’s my code for set the value for the class
CHighScore chigh = new CHighScore();
chigh.SingleScore = Score;
chigh.SinglePlayer = TxtLoginName.Text;
I’ve learnt C# from internet. The web site is www.functionx.com/csharp/
I also sending my whole project (I mean to say developing project, not finished yet !!!) if anyone like to see it.
Fee Aamanillah