Skip to content
Loading
  • Bikesh Srivastava
    0
    Hi Gova,
    Its working code on my machine.try this.mark as answer if resolve your query.
    1. usingSystem;
    2. usingSystem.Net.NetworkInformation;
    3. usingSystem.Net;
    4. usingSystem.Net.Sockets;
    5. namespaceExample
    6. {
    7. classProgram
    8. {
    9. staticvoidMain(string[]args)
    10. {
    11. stringnum="10,20,30,40";
    12. string[]val=num.Split(',');
    13. intsum=0;
    14. inttemp=0;
    15. for(inti=0;i
    16. {
    17. sum+=int.Parse(val[i]);
    18. }
    19. Console.Write(sum);
    20. Console.Read();
    21. }
    22. }
    23. }
    0
  • Tapan Patel
    0
    You can do something as below. The code is using action as parameter to Foreach loop on the collection of string. So even if you run to empty string (considering last comma), it shouldn't err out.
    1. List<string>lst="878.97,878.97".Split(',').ToList();
    2. doublesum=0;
    3. lst.ForEach(e=>{if(!string.IsNullOrEmpty(e))sum+=double.Parse(e);});
    4. Console.WriteLine(sum);
    Please mark it as answer if it resolves the issue.
    0