dieucay555
11-11-2011, 16:22
Mình viết extension method đơn giản,convert IEnumerable sang ObservableCollection. Code như sau :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Data;
namespace BookStore.Helper
{
public static class ExtensionMethods<T> where T: class
{
public static ObservableCollection<T> ToObservableCollection(this IEnumerable<T> source)
{
ObservableCollection<T> target = new ObservableCollection<T>();
foreach (T item in source)
target.Add(item);
return target;
}
}
}
mà toàn bị báo lỗi "Error 5 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?) "
Làm thế nào để fix lỗi này được nhỉ, mình viết trên VS2k10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Data;
namespace BookStore.Helper
{
public static class ExtensionMethods<T> where T: class
{
public static ObservableCollection<T> ToObservableCollection(this IEnumerable<T> source)
{
ObservableCollection<T> target = new ObservableCollection<T>();
foreach (T item in source)
target.Add(item);
return target;
}
}
}
mà toàn bị báo lỗi "Error 5 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?) "
Làm thế nào để fix lỗi này được nhỉ, mình viết trên VS2k10