无法解析符号 T
我对 ObservableCollection 类有疑问。 我无法解决这个问题。
using System.Collections.ObjectModel;
#region ViewModelProperty: CustomerList
private ObservableCollection<T> _customerList = new ObservableCollection<T>();
public ObservableCollection<T> CustomerList
{
get
{
return _customerList;
}
set
{
_customerList = value;
OnPropertyChanged("CustomerList");
}
}
#endregion
我的 ObservableCollection 类继承了 ViewModelBase:
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
知道吗,问题出在哪里?
I have a problem with ObservableCollection Class. I cant resolve this.
using System.Collections.ObjectModel;
#region ViewModelProperty: CustomerList
private ObservableCollection<T> _customerList = new ObservableCollection<T>();
public ObservableCollection<T> CustomerList
{
get
{
return _customerList;
}
set
{
_customerList = value;
OnPropertyChanged("CustomerList");
}
}
#endregion
My class with the ObservableCollection inherits ViewModelBase:
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
any idea, where is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
T
只是一个占位符。 您需要在某处为T
提供实际类型。例如,如果您有
List
,则可以创建List
或List
(T
code> 是符合给定约束的任何其他类型)。 即,在第一种情况下,T
是int
,在第二种情况下,T
是string
。T
is just a placeholder. You need to supply an actual type somewhere forT
.E.g. if you have
List<T>
, you could make aList<int>
orList<string>
(T
is any other type which fits the given constraints). I.e.T
isint
in the first case andstring
in the second.我认为当您阅读一点 泛型< /a>
您可以这样做:
然后,您有一个类型化集合,它将能够存储 Customer 类的实例(以及从 Customer 继承的子类的实例)。
因此,如果您想要一个能够添加多种类型实例的集合,您可以创建一个基类(或接口),并从该基类继承或实现此接口,然后创建一个 ObservableCollection例如,前。
I think that it will become clear to you when you read up a bit on Generics
You could do it like this:
Then, you have a typed collection which will be able to store instances of the Customer class (and also instances of subclasses that inherit from Customer).
So, if you want to have a collection where you want to be able to add instances of multiple types, you could create a base-class (or interface), and inherit from that base-class or implement this interface, and create an ObservableCollection instance for ex.
如前所述,T 是占位符。 你可能想要这样的东西:
As previously posted, T is a placeholder. You probably want something like: