[英]How to check dynamically whether an index in the array exists or not?
我已經將JSON字符串反序列化為current_location,EducationHistory和WorkHistory的數組。
我如何動態解決此問題並將值存儲在數據庫中
編輯:
Result soap = serializer.deserialize<Result>(ser);
foreach(var data in soap.data)
{
int lenght= soap.data.educationhistory.Length;
foreach(var education in soap.data.educationhistory)
{
// my insert query
}
}
現在的問題是,我還必須為work_history運行一個foreach循環。 一個foreach循環中的兩個foreach循環是一個問題。 如何在最少使用循環的情況下完成?
您可以檢查數組的長度:
int length = soap.data.education_history.Length; // gives you 2
一旦知道長度,便知道索引必須小於此長度。 當然,如果只循環遍歷此數組,則索引不會有任何問題:
foreach (var education in soap.data.education_history)
{
// TODO: save the education in your database
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.