対応する名前とスコアを含む dataTable があります。スコアに基づいて降順に並べ替えたいと思います。
DB.cs のコードは次のとおりです。
public class DB
{
public DataTable GetData()
{
string spName = "GetTime";
Connection.Open();
SqlCommand command = new SqlCommand(spName, Connection);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = command.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Time");
while (reader.Read())
{
DataRow dr = dt.NewRow();
dr["Name"] = Convert.ToString(reader["name"]);
dr["Time"] = Convert.ToInt32(reader["timeScore"]);
dt.Rows.Add(dr);
}
Connection.Close();
return dt;
}
}
これは Form3.cs にあります
public partial class Form3 : Form
{
private Form2 form2;
public Form3()
{
InitializeComponent();
loadData();
}
public void loadData()
{
form2 = new Form2();
DataTable dt2 = form2.db.GetData();
dgvScore.DataSource = dt2;
}
}
comparer
Javaのように並べ替えるにはどうすればよいですか? 簡単なアルゴリズムの答えが欲しいだけです。ご協力いただきありがとうございます。