using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace demo1
{
class Program
{
// static char[] Tranform = new char[36] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
//static string Tranform10To36Hex(long vl_value)
// {
// int i;
// byte[] a = new byte[8];
// byte[] b = new byte[8];
// string Hex36Str;
// for (i = 0; i < 7; i++)
// {
// if (vl_value < 36)
// {
// a[i] = Convert.ToByte(vl_value.ToString());
// break;
// }
// a[i] = Convert.ToByte(vl_value % 36);
// vl_value = vl_value / 36;
// }
// for (i = 0; i < 7; i++)
// {
// b[i] = Convert.ToByte(Tranform[Convert.ToInt32(a[7 - i - 1])]);
// }
// Hex36Str = System.Text.Encoding.ASCII.GetString(b);
// return Hex36Str;
// }
static void Main(string[] args)
{
//WebReference.CargetoilOvaluesService cgo = new WebReference.CargetoilOvaluesService();
//decimal dd = cgo.GetOvalue("460020831369683", Convert.ToDecimal(171.50));
//Console.WriteLine(dd);
//long aa = 2173500393;
//string bb=Tranform10To36Hex(aa);
//Console.WriteLine(bb);
List<Student> list = new List<Student>()
{
new Student{Name="aaa",ClassName="a",Age=20,StuNo="a001"},
new Student{Name="bbb",ClassName="a",Age=18,StuNo="a003"},
new Student{Name="ccc",ClassName="b",Age=20,StuNo="b001"},
new Student{Name="ddd",ClassName="b",Age=20,StuNo="b045"},
new Student{Name="eee",ClassName="c",Age=20,StuNo="c001"},
new Student{Name="fff",ClassName="c",Age=20,StuNo="c008"},
new Student{Name="ggg",ClassName="c",Age=20,StuNo="c050"},
new Student{Name="hhh",ClassName="c",Age=20,StuNo="c007"}
};
Dictionary<string, List<Student>> stuGroup = new Dictionary<string, List<Student>>();
foreach (Student item in list)
{
if (!stuGroup.Keys.Contains(item.ClassName))
{
stuGroup.Add(item.ClassName, new List<Student>());
}
stuGroup[item.ClassName].Add(item);
}
foreach (KeyValuePair<string, List<Student>> item in stuGroup)
{
Console.WriteLine("班级:" + item.Key);
foreach (Student stu in item.Value)
{
Console.WriteLine("姓名:" + stu.Name + "\t班级:" + stu.ClassName + "\t年龄:" + stu.Age + "\t学号:" + stu.StuNo);
}
}
Console.Read();
Console.Read();
}
}
class Student
{
public string Name { get; set; }
public string ClassName { get; set; }
public int Age { get; set; }
public string StuNo { get; set; }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace demo1
{
class Program
{
// static char[] Tranform = new char[36] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
//static string Tranform10To36Hex(long vl_value)
// {
// int i;
// byte[] a = new byte[8];
// byte[] b = new byte[8];
// string Hex36Str;
// for (i = 0; i < 7; i++)
// {
// if (vl_value < 36)
// {
// a[i] = Convert.ToByte(vl_value.ToString());
// break;
// }
// a[i] = Convert.ToByte(vl_value % 36);
// vl_value = vl_value / 36;
// }
// for (i = 0; i < 7; i++)
// {
// b[i] = Convert.ToByte(Tranform[Convert.ToInt32(a[7 - i - 1])]);
// }
// Hex36Str = System.Text.Encoding.ASCII.GetString(b);
// return Hex36Str;
// }
static void Main(string[] args)
{
//WebReference.CargetoilOvaluesService cgo = new WebReference.CargetoilOvaluesService();
//decimal dd = cgo.GetOvalue("460020831369683", Convert.ToDecimal(171.50));
//Console.WriteLine(dd);
//long aa = 2173500393;
//string bb=Tranform10To36Hex(aa);
//Console.WriteLine(bb);
List<Student> list = new List<Student>()
{
new Student{Name="aaa",ClassName="a",Age=20,StuNo="a001"},
new Student{Name="bbb",ClassName="a",Age=18,StuNo="a003"},
new Student{Name="ccc",ClassName="b",Age=20,StuNo="b001"},
new Student{Name="ddd",ClassName="b",Age=20,StuNo="b045"},
new Student{Name="eee",ClassName="c",Age=20,StuNo="c001"},
new Student{Name="fff",ClassName="c",Age=20,StuNo="c008"},
new Student{Name="ggg",ClassName="c",Age=20,StuNo="c050"},
new Student{Name="hhh",ClassName="c",Age=20,StuNo="c007"}
};
Dictionary<string, List<Student>> stuGroup = new Dictionary<string, List<Student>>();
foreach (Student item in list)
{
if (!stuGroup.Keys.Contains(item.ClassName))
{
stuGroup.Add(item.ClassName, new List<Student>());
}
stuGroup[item.ClassName].Add(item);
}
foreach (KeyValuePair<string, List<Student>> item in stuGroup)
{
Console.WriteLine("班级:" + item.Key);
foreach (Student stu in item.Value)
{
Console.WriteLine("姓名:" + stu.Name + "\t班级:" + stu.ClassName + "\t年龄:" + stu.Age + "\t学号:" + stu.StuNo);
}
}
Console.Read();
Console.Read();
}
}
class Student
{
public string Name { get; set; }
public string ClassName { get; set; }
public int Age { get; set; }
public string StuNo { get; set; }
}
}