Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created September 10, 2014 07:10
Show Gist options
  • Save masaru-b-cl/73b01ad7ea3687908784 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/73b01ad7ea3687908784 to your computer and use it in GitHub Desktop.
好きな項目でMax/Minするケース
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
namespace UnitTestProject2
{
class Person : IComparable<Person>
{
public int Age { get; set; }
public string Name { get; set; }
public int CompareTo(Person other)
{
return this.Age.CompareTo(other.Age);
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var source = new Person[]
{
new Person{Age=24, Name="John"},
new Person{Age=19, Name="Jack"},
new Person{Age=32, Name="Brown"},
};
Assert.AreEqual("Brown", source.Max().Name); // Sucess
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment