如何在c#中访问内部列表项 [英] How to Access inner list item in c#
本文介绍了如何在c#中访问内部列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 c# 语言开发 Windows Phone 应用程序,但在访问 c# 中的内部列表项时遇到了问题.
I am working on windows phone app using c# language and I am facing issue to access inner list item in c#.
我有以下 json 类
I have following json class
public List<List<string>> Professions { get; set; }
获取 Json 网络服务响应的代码
code for getting response from Json web service
list_professions.ItemsSource = rootObject.result.Professions;
界面
<phone:LongListSelector Name="list_professions" Tap="list_professions_Tap"
IsGroupingEnabled="True">
</phone:LongListSelector>
JSON 响应喜欢
{"flag":"1","message":"Result Found","result":{"Professions":[["Abortion Services","Abortion Counsellor","Abortion Clinic"],["Access Consultant","Access Control Systems","Access Equipment","Designer","dshajkfhksdajkfhafkdjsh","hjkrty"],["Accident Claims"],["Accountant","Book-Keeping","Auditing","VAT Returns","Business Advice","Payroll","test","First Custom Service"],["Acoustic Services"],["Acturary","Risk Assessor"],["Acupunctur","Herbal Remedies","Massage","Healing","Accupressure"],["Addiction Counsellor","Alcohol Addiction","Drug Addiction","Counselling","Psychotherapy"],["Adhesive Products"],["Adoption & Fostering"],["Adult Education Centres","Adult Tuition","Private Tuition","ESL","Home Tuition"],["Advertising Services","Advertising Agency","Marketing Services","Online Marketing","Press Marketing"],["Aerials","Satellite Dishes","Cable TV"],["Aeronautical Instruments"],["Aerosols"],["After School Care"],["Agricultural Services","Agricultural Vehicles"],["Air Compressors"],["Air Conditioning Services","Heating Services","Air Purification Equipment"]]}}
推荐答案
你只是要求这个吗?
var firstItemOfProfession0 = (Professions[0])[0];
如果要循环,请使用双 foreach
use a double foreach if you want to loop through
foreach(var profession in Professions)
{
foreach(var subProfession in profession)
{
Console.Writeline(subProfession);
}
}
如果您需要扁平化列表,请使用 Linq:
if you need to have a flatten list use Linq:
var flattenProfessions = Professions.SelectMany(x => x).ToList();
这篇关于如何在c#中访问内部列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文