hi,
i am learning .net language.. and at the beginning level.i am having a problem in following code:
Prob1: i am not able to print the value of sal[] which is array of instances.
Prob2: Which sorting method is being used (by the system) in Array.Sort().
Prob3: in output of above code,comparing is unnecessarily getting performed repeatedly.Am I missing any concept here?
i am learning .net language.. and at the beginning level.i am having a problem in following code:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace interface_IComparable_practice1
{
class cur : IComparable<cur>
{
int d, c;
public cur(int d1,int c1)
{
d=d1;
c=c1;
}
public int CompareTo(cur other)
{
int tval=(this.d*100)+this.c;
int otval=(other.d*100)+other.c;
Console.WriteLine("1->{0},2->{1}\n",tval.ToString(),otval.ToString());
Console.WriteLine(tval.CompareTo(otval).ToString());
return(tval.CompareTo(otval));
}
}
class Program
{
static void Main(string[] args)
{
cur[] sal = { new cur(100, 00), new cur(70, 08), new cur(80, 53), new cur(20, 78) };
Array.Sort(sal);
//foreach(cur i in sal )
for(i=0;i<4;i++)
Console.WriteLine("\n{0}",sal[i].ToString());
Console.Read();
}
}
}
Prob1: i am not able to print the value of sal[] which is array of instances.
Prob2: Which sorting method is being used (by the system) in Array.Sort().
Prob3: in output of above code,comparing is unnecessarily getting performed repeatedly.Am I missing any concept here?
Comment