2016-03-31 21 views
0

に各項目を渡すと、私はそう、このは、ループおよび方法

list<string> OldlicenseList = new List<string>{"abcs", "rtets", "taya", "tctct"}; //sample data 

list<string> subscriptionList = new List<string> {"udud", "ydyyd" , "tsts","tstst", "hghs"} //Sample data 

私はここに私が必要

foreach (var strOldLicense in OldlicenseList) 
    { 
     foreach (var subscriptionList in objSubscription.lstClsLicense) 
     { 
       newLicenseList.Add(subscriptionList.license_key); 
       isInserted = _objcertificate.UpdateClpInternalLicense(subscriptionKey, _objUserInfo.GetUserAcctId(), strOldLicense, subscriptionList.license_key, expiryDT); 

       if (!isInserted) 
       { 
        new Log().logInfo(method, "Unable to update the Subscription key." + certID); 
        lblErrWithRenewSubKey.Text = "Application could not process your request. The error has been logged."; 
        lblErrWithRenewSubKey.Visible = true; 
        return; 
       } 
       insertCount++; 

       if (insertCount >= 4) 
       { 
         break; 
       } 
     } 

    } 

の下に、次のようにやっているように、文字列の2つのリストを持っています両方のリストからそれぞれのアイテムをメソッドUpdateClpInternalLicenseに渡し、2番目のリスト(subscriptionList)に5個のアイテムがありますが、そのメソッドに5番目のアイテムの送信を停止する必要があります。

第一のリスト内の4つの項目があるので、私は、各リストから1つのアイテムを渡す必要..

を私は方法を上述試みたが、問題が一旦内側ループが完了している..それは再び介してループ意志

4回の反復まで、その方法、第4回の繰り返しの後、私は両方のループから出てくる必要がある。..事前に

いずれかが非常に感謝されることを、任意のアイデアを提案してくださいだろう。..

を感謝..

+0

Mmm ...別の 'if(insertCount> = 4){ブレーク; } 'あなたの最初のforeachで...? –

+0

'' 'foreach'''の代わりに' '' for'''を使ってみましたか? –

+0

'foreach'の代わりに単純な 'for'ループを使用して、何度も繰り返し実行してみましょう – Nitin

答えて

1

これを行うことができます:

var query = 
    from strOldLicense in OldlicenseList 
    from subscriptionList in objSubscription.lstClsLicense 
    select new { strOldLicense, subscriptionList }; 

foreach (var x in query) 
{ 
    newLicenseList.Add(x.subscriptionList.license_key); 
    isInserted = _objcertificate.UpdateClpInternalLicense(subscriptionKey, _objUserInfo.GetUserAcctId(), x.strOldLicense, x.subscriptionList.license_key, expiryDT); 

    if (!isInserted) 
    { 
     new Log().logInfo(method, "Unable to update the Subscription key." + certID); 
     lblErrWithRenewSubKey.Text = "Application could not process your request. The error has been logged."; 
     lblErrWithRenewSubKey.Visible = true; 
     return; 
    } 
    insertCount++; 

    if (insertCount >= 4) 
    { 
     break; 
    } 
} 

これにより、反復処理中のリストが1つ減り、breakが機能します。

+0

サポートに感謝します:) –

+0

私たちはこの問題に「x .strOldLicense "この変数がクエリをループするときに最初のライセンスだけを保持するたびに.. ..このことについて助けてください。 –

+0

@EnigmaState - ' query'列挙型全体を実行してみてください。それはうまくいくはずです。次の 'x.strOldLicense'値を取得する前に、' insertCount'が '4'を超えていると思います。 – Enigmativity

関連する問題