本文整理汇总了C#中Category.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Category.CompareTo方法的具体用法?C# Category.CompareTo怎么用?C# Category.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category.CompareTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareToTest
public void CompareToTest()
{
Category a = new Category("Hello", "Good\\Bye");
Category c = new Category("Zzzzz", "AAAA");
Category d = new Category("Hello", "AAAA");
var source = new List<Category> {a, c, d};
var expected = new List<Category> {d, a, c};
source.Sort();
Assert.IsTrue(source.SequenceEqual(expected));
Assert.AreEqual(-1, a.CompareTo(null));
}
示例2: buttonSave_Click
/// <summary>
/// Save button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSave_Click(object sender, EventArgs e)
{
List<KeyValuePair<String, String>> formData = new List<KeyValuePair<String, String>>
{
new KeyValuePair<String, String>("category_id", textBoxId.Text),
new KeyValuePair<String, String>("name", textBoxNume.Text),
};
Category category = new Category();
category.setData(formData);
if (textBoxId.Text != "")
{
Category compare = new Category();
compare.load(textBoxId.Text);
if (category.CompareTo(compare) == 1)
{
MessageBox.Show("Trebuie sa faceti cel putin o modificare!", "Atentie");
return;
}
}
if (category.save())
{
MessageBox.Show("Categoria a fost salvata!");
this.Dispose();
}
else
{
MessageBox.Show("A intervenit o eroare!");
}
}