none
LINQ String[] C# iteration RRS feed

  • Question

  • hello,

    private ResponseEntity GetResponseEntity(Questions questionsList)
            {
                //prepare reponse to be displayed.
                ResponseEntity objReponseEntity = new ResponseEntity();
    
                //Getting all the distinct question ids
                objReponseEntity.questionsCount= questionsList.Items.Count();
    
                for (int count = 0; count < questionsList.Items.Count(); count++)
                {
                    objReponseEntity.viewCount += questionsList.Items[count].ViewCount;
                }
                
                List<string[]> listOfTags = new List<string[]>();
                for (int count = 0; count < questionsList.Items.Count(); count++)
                {
                    listOfTags.AddRange(questionsList.Items[count].Tags.ToList()
                           .Select(a => a.Split(','))
                           .ToList());              
                }
    
                objReponseEntity.tagsDisplayed = listOfTags.Select(i => i.ToString()).ToArray();            
                return objReponseEntity;
            }

     internal class Item
        {
            [JsonProperty("tags")]
            public string[] Tags { get; set; }
    
            [JsonProperty("owner")]
            public Owner Owner { get; set; }
    }

    public class ResponseEntity
        {
            public int questionsCount { get; set; }
            public int viewCount { get; set; }
            public string[] tagsDisplayed { get; set; }
        }

    Can somebody please recommend me a approach on how do I parse this and show it console app.

    I was also think of change string[] tags in my response class to List<string>....

    Please suggest a sample linq query will be or great help...

    thanks

    Friday, June 27, 2014 2:19 PM

Answers

  • string display = string.Empty;
                listOfTags.ToList().ForEach(p => display += p + " ");
    Console.WriteLine(display);

    • Marked as answer by StSingh Saturday, June 28, 2014 2:39 PM
    Friday, June 27, 2014 5:14 PM