//test.cs
using System;
class Student: IComparable
{
string name;
int Grade;
bool Listen;
public Student(string n)
{
name = n;
Grade = 0;
Listen = false;
}
public void print()
{
Console.WriteLine(name);
}
public string getname()
{
return name;
}
#region
public int CompareTo(Student b)
{
return this.name.CompareTo(b.getname());
}
#endregion
static void Main(string[] args)
{
}
}
//prog.cs
class Program
{
static void Main(string[] args)
{
Student a = new Student ("aa");
Student b = new Student ("bb");
Swap(ref a, ref b);
a.print();
b.print();
}
static void Swap(ref Student a , ref Student b)
{
Student tem = a;
a = b;
b = tem;
Student[] stu = new Student[5];
stu[0] = new Student("bb");
stu[1] = new Student("aa");
stu[2] = new Student("dd");
stu[3] = new Student("cc");
stu[4] = new Student("ee");
foreach(Student s in stu)
s.print();
var stu2 = stu.Orderby(o=>o.name);
foreach(Student s in stu2)
s.print();
}
}
//public class Cmp : IComparer<Student>
//{
// int IComparer<Student>.Compare(Student a, Student b)
// {
// return a.getname()< b.getname();
// }
package testcase;
import static org.junit.Assert.*;
import org.junit.Test;
import demo.test;
public class mytest {
@Test
public void testAdd() {
assertEquals(5.0,test.add(2, 3), 0.0);
}
@Test
public void another() {
assertEquals(1.0,test.add(2, 3), 0.0);
}
}
package demo;
public class test {
public static int add(int a,int b)
{
return a+b;
}
}