Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:44:12+00:00 2026-06-13T11:44:12+00:00

string sStoreStockFeed = ; string sSeparator = ; var distinctStoreIDList = skuStoreStockLevels.Select(x => x.Item1).Distinct();

  • 0
string sStoreStockFeed = "";
string sSeparator = "";

var distinctStoreIDList = skuStoreStockLevels.Select(x => x.Item1).Distinct();

    foreach (var storeID in distinctStoreIDList)
    {
        foreach (var item in skuStoreStockLevels)
        {
            if (item.Item1 == storeID)
            {
               // add this one to a job for this store
                       sStoreStockFeed += sSeparator + item.Item1.ToString() + "," + item.Item2.ToString() + "," + item.Item3.ToString();
                       sSeparator = "|";
            }
        }
      // some code to process the string before moving on
      sStoreStockFeed = "";
      sSeparator = "";
    }

In the above code snippet skuStoreStockLevels just happens to be a List of type Tuple and Item1 is the StoreID. having got a distinct list it then iterates through the (non-distinct) list to get every applicable item. The inefficiency is that the (big) inner list is iterated throuh repeatedly for each distinct item (StoreID).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:44:13+00:00Added an answer on June 13, 2026 at 11:44 am

    UPDATE: pure LINQ solution. This will give you list of strings, created for each group of items.

    var query = skuStoreStockLevel.GroupBy(x => x.Item1)
                    .Select(g => g.Aggregate(new StringBuilder(),
                                             (sb, x) => sb.AppendFormat("{0}{1},{2},{3}", sSeparator, x.Item1, x.Item2, x.Item3),
                                             (sb) => sb.ToString()));
    
    foreach(var feed in query)
        // some code to process the string before moving on
    

    Also there are other options – ordering of sequence. Equal items will follow one after another.

    int storeID = -1;
    StringBuilder builder = new StringBuilder();
    
    foreach (var item in skuStoreStockLevel.OrderBy(x => x.Item1))
    {
        builder.AppendFormat("{0}{1},{2},{3}", sSeparator, item.Item1, item.Item2, item.Item3);
        if (item.Item1 != storeID)
        {
            // some code to process the string before moving on
            storeID = item.Item1;
        }       
    }
    

    Or you can use grouping

    StringBuilder builder = new StringBuilder();
    
    foreach (var storeGroup in skuStoreStockLevel.GroupBy(x => x.Item1))
    {
        foreach (var item in storeGroup)
              builder.AppendFormat("{0}{1},{2},{3}", sSeparator, item.Item1, item.Item2, item.Item3);        
    
        // some code to process the string before moving on
    }
    

    And, of course, it’s better to use StringBuilder for creating strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string one = find; combobox1.text = one; I want to use one i.e string
string content= <br /><br /><a href=need to replace this url>Cooking School</a><br /><br /><a href=http://www.sdlm.com>Feed
string s = abcabcabcabcabc; var foundIndexes = new List<int>(); The question came from the
String q = SELECT attr FROM students foo =? AND bar = ?; PreparedStatement
String pnumber = request.getParameter(pnumber); ResultSet rs = DAO.fetch(SELECT * FROM Products Where ProductNumber ='
string DownloadDirectoryPath = @C:\\Program Files\\companyname\\productname\\username\\0\\2012081617085746 (this is the path i get from the sql
String DocLocation = System.AppDomain.CurrentDomain.BaseDirectory + Files/test.pdf; // or String DocLocation = Url.Content(~/Files/test.pdf); var document
string tags = 9,3,12,43,2 List<int> TagIds = tags.Split(','); This doesn't work cause the split
String data=this we want append in that file; byte[] getbyte = data.getBytes(); outputstream.write(getbyte); outputstream.flush();
string []URL = {www.facebook.com,www.orkut.com,www.yahoo.com}; Int32 result = URL.Length; SetPolicyURL( URL,result ); this is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.