本文介绍了在C#4中转换泛型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能帮我将基类转换为数据集合的数组列表
Hi,
Can anyone help me in casting the base class to Data Collection for an array list
dataServiceColl = new DataServiceCollectiongmcApp>();
GridView1.DataSource = dataServiceColl;
GridView1.EmptyDataText = "No Data Found.";
if (!Page.IsPostBack){
Uri requestUri = GetQueryRequestUri();
try {
if(authenticationRequired)
{
service.SendingRequest += new EventHandler<sendingrequesteventargs>(service_SendingRequest);
}
logMessage.AppendLine(String.Format("Request uri = ''{0}''", requestUri.OriginalString));
var result = service.Execute<gmcapp>(requestUri);
dataServiceColl.Load(result);
/* Here I am querying the data ,Here I need to type cast */
GridView1.DataSource = dataServiceColl.Select(t => t.prod_desc ="Edibleitem");
logMessage.AppendLine(String.Format("Retrieved ''{0}'' items", dataServiceColl.Count</gmcapp></sendingrequesteventargs>
有人可以帮我转换上面代码中注释的行吗?
Can anyone help me in casting the line i commented in the above code?
推荐答案
// Only select on class ProducClass.
GridView1.DataSource = dataServiceColl.OfType<producclass>().Select(t => t.prod_desc ="EdibleItem");
/* Here I am querying the data ,Here I need to type cast */
GridView1.DataSource = dataServiceColl.Select(t => t.prod_desc ="Edibleitem");
解决方案:
Solution :
/* Here I am querying the data ,Here I need to type cast */
GridView1.DataSource = dataServiceColl.Cast<yourcastingclass>.Select(t => t.prod_desc ="Edibleitem");</yourcastingclass>
应该可以.
这可能对您有用:)
谢谢:)
It should work.
This may be usefull to you :)
Thanks :)
这篇关于在C#4中转换泛型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!