Hi,
How to update the foreach values at a short in mvc5 . I am fetching the values in foreach loop after that how to update that values?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mukesh KumarRank #119 · 18.2K reputationPosted Oct 11, 2015, 9:58 PM EDT
Harpreet60 reputationPosted Oct 11, 2015, 10:03 PM EDT
Mukesh KumarRank #119 · 18.2K reputationPosted Oct 11, 2015, 10:11 PM EDT
Harpreet60 reputationPosted Oct 11, 2015, 10:19 PM EDT
Mukesh KumarRank #119 · 18.2K reputationPosted Oct 11, 2015, 10:26 PM EDT
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; using System.Data.Sql; using System.Data; namespace Linq_Grouping { class Program { static void Main(string[] args) { Console.WriteLine("Enter your choice."); int choice = int.Parse(Console.ReadLine()); if (choice == 1) ExecuteLinqForXML(); Console.ReadLine(); } static void ExecuteLinqForXML() { Random rnd = new Random(); XElement Customers = new XElement("Customers"); for (int i = 0; i 25; i++) { Customers.Add( new XElement("Customer", new XElement("Id", ("cust_id" + (i + 1))), new XElement("Name", "Customer" + (i + 1)), new XElement("Category", "Cat" + ((i + 1)) / 4), new XElement("Sales", (rnd.Next(100, 1000))) ) ); } var results = from p in Customers.Descendants("Customer") group p by p.Element("Category").Value into grps select new { Key = grps.Key, Values = grps, TotalSales = grps.Sum (g => decimal.Parse(g.Element("Sales").Value)), Total = grps.Count(), AvgSales = grps.Average (g => decimal.Parse(g.Element("Sales").Value)), MaxSales = grps.Max(g => decimal.Parse(g.Element("Sales").Value)), MinSales = grps.Min(g => decimal.Parse(g.Element("Sales").Value)) }; foreach (var result in results) { Console.WriteLine("Category - " + result.Key); Console.WriteLine("Total Sales : " + result.TotalSales + " Average Sales : " + result.AvgSales + " Maximum Sales : " + result.MaxSales + " Minimum Sales : " + result.MinSales); Console.WriteLine("ID\t\t\tName\t\t\tCategory\tSales"); foreach (XElement Customer in result.Values) { Console.WriteLine( Customer.Element("Id").Value + "\t\t" + Customer.Element("Name").Value + "\t\t" + Customer.Element("Category").Value + "\t\t" + Customer.Element("Sales").Value + "\t\t" ); } } } } }Harpreet60 reputationPosted Oct 11, 2015, 10:30 PM EDT
Mukesh KumarRank #119 · 18.2K reputationPosted Oct 11, 2015, 10:32 PM EDT
Harpreet60 reputationPosted Oct 11, 2015, 10:47 PM EDT