我想將C#2008代碼轉換爲代碼C#2005,我不明白命令C#2008切換到C#2005,請參閱下面的錯誤代碼是否可以解決錯誤命令呢?運行在C#2008中的代碼非常好將C#2008代碼轉換爲C#2005代碼?
private void textBox1_TextChanged(object sender, EventArgs e)
{
string str = textBox1.Text.Trim();
if (!string.IsNullOrEmpty(str))
{
// Error in here
Expression<Func<CustomData, bool>> expr = n => GetCondition(n, str);
this.gridControl1.DataSource = this.lstCustomData.Where<CustomData>(expr.Compile()).ToList();
}
else
this.gridControl1.DataSource = this.lstCustomData;
this.gridControl1.RefreshDataSource();
}
public class CustomData
{
// Error in here
public int col1 { get; set; }
public string col2 { get; set; }
public string col3 { get; set; }
public int col4 { get; set; }
}
我已經固定的代碼的格式,但我離開你的原句,因爲我不明白足以改善它。請注意,涉及的語言版本是3和2 ... 2008和2005是Visual Studio的版本。現在,還不清楚*爲什麼要使用C#2,而不是更清晰的C#3代碼。你能解釋一下嗎?如果僅僅是你不瞭解C#3的特性(lambda表達式,擴展方法,自動實現的屬性),你最好不要學習這些。 – 2015-03-03 07:12:18
另一個很好的問題是你使用的是什麼版本的.NET框架,因爲語言只是謎題的一部分 - 如果你使用相應的.NET 2.0,它也會錯過一些類型。 – 2015-03-03 07:15:26
Well - GetCondition根據用於過濾lstCustomData的輸入返回某些內容。弄清楚GetCondition是如何工作的,你可以簡單地重寫它......但它引發了這個問題;是否需要運行C#2並且無法升級到3.5? – 2015-03-03 07:15:36