C# 在字串上使用>,<等運算時,會拋出編譯錯誤的訊息,
C# 在字串上使用>,<等運算時,會拋出編譯錯誤的訊息,
可改寫如下:
static void Test2()
{
DataClasses1DataContext context = new DataClasses1DataContext();
var result = from s1 in context.Customers where
s1.CustomerID.CompareTo("VINET") >= 0 &&
s1.CustomerID.CompareTo("WAVIN") <= 0
select s1;
foreach (var item in result)
{
Console.WriteLine(item.CustomerID);
}
Console.ReadLine();
}
{
DataClasses1DataContext context = new DataClasses1DataContext();
var result = from s1 in context.Customers where
s1.CustomerID.CompareTo("VINET") >= 0 &&
s1.CustomerID.CompareTo("WAVIN") <= 0
select s1;
foreach (var item in result)
{
Console.WriteLine(item.CustomerID);
}
Console.ReadLine();
}
CompareTo的回傳值為: 大於回傳1,小於回傳-1,等於回傳0,
所以>=0,即為大於等於VINET