如何从列表中选择一个特定的列表项 [英] how to select a particular list item from a LIST
本文介绍了如何从列表中选择一个特定的列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个< list>作为projectcollects
公共列表< 字符串 > ListAllProjects
{
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(@"http://servername/");
tfs.EnsureAuthenticate();
WorkItemStore workItemStore =新的WorkItemStore(@"http://servername/tfs/POC");
List < 字符串 > list =新列表< 字符串 > ( );
foreach(workItemStore.Projects中的项目pr)
{
list.Add(pr.Name);
}
如果(list.Count == 0)
list.Add(未找到");
返回清单;
}
现在我要在该列表中选择ListAllProjects.item =="projectname1".
该程序从TFS服务器捕获所有项目.
注意:此处的服务器名称说明了TFS服务器名称
请帮助我
感谢®ards
nareshrajuu
解决方案
只需遍历您的列表,然后将其与"projectname1"进行比较:
foreach (字符串项在 ListAllProjects中) { 如果(项目== " ) { // 做您想做的事 } }
致以最诚挚的问候
非常感谢您的重播.
我这样写
公共列表< string> ListAllProjects { TeamFoundationServer teamFoundationServer = TeamFoundationServerFactory.GetServer( @" ); teamFoundationServer.Authenticate(); WorkItemStore workItemStore = 新 WorkItemStore( @" ); List< string> list = 新 List< string>(); foreach (项目pr in workItemStore.Projects中的项目) { list.Add(pr.Name); } 如果(list.Count == 0 ) list.Add(" ); 其他 { foreach (字符串 item in ListAllProjects中的项目) { 如果(项目== " ) { 返回项目; } } }
但没有获得该特定的项目名1.
请帮我,我该怎么写.还有其他方法吗?
Bjorn Ranft,
感谢您的建议,它正在工作.
hi
i have a <list> as projectcollects
public List<string> ListAllProjects
{
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(@"http://servername/");
tfs.EnsureAuthenticate();
WorkItemStore workItemStore = new WorkItemStore(@"http://servername/tfs/POC");
List<string> list = new List<string>();
foreach (Project pr in workItemStore.Projects)
{
list.Add(pr.Name);
}
if (list.Count == 0)
list.Add("Not Found");
return list;
}
now i want to select ListAllProjects.item=="projectname1" in that list.
this program captures all projects from TFS server.
note: here servername illustrate the TFS server name
pls help to me
thanks ®ards
nareshrajuu
解决方案
Hi,
just go through your list and compare it with "projectname1":
foreach(string item in ListAllProjects) { if(item == "projectname1") { //do what you want to do } }
With Best Regards
thanks a lot to your replay.
i written like this
public List<string> ListAllProjects { TeamFoundationServer teamFoundationServer = TeamFoundationServerFactory.GetServer(@"http://tfsservername/"); teamFoundationServer.Authenticate(); WorkItemStore workItemStore = new WorkItemStore(@"http://tfsservername"); List<string> list = new List<string>(); foreach (Project pr in workItemStore.Projects) { list.Add(pr.Name); } if (list.Count == 0) list.Add("Not Found"); else { foreach(string item in ListAllProjects) { if(item == "projectname1") { return item; } } }
but not getting that particular projectname1.
please help to me how can i will write.is there anotherway?
hi Bjorn Ranft,
thank for your suggestion, it was working.
这篇关于如何从列表中选择一个特定的列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文