无法更新列表中的值 [英] Not able to update values in a list

查看:77
本文介绍了无法更新列表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我需要更新列表中的值...我已经编写了一个方法但是值没有得到更新。请帮我识别问题



我的班级结构



Hi Friends,

I need to update values in a list... for which i have written a method but values is not get updated. please help me to identiffy the issue

My class structure

 public class TaxBucket
    {
        public int Year { get; set; }
        public List<TaxBucketSub> taxbucketsub { get; set; }

    }
    public class TaxBucketSub
    {
        public int PortfolioID { get; set; }
        public CarryForwards carryforwards { get; set; }
        public CarryForwards buckets { get; set; }
        public CarryForwards currentyearvalue { get; set; }
    }
public class CarryForwards
    {
        public double taxDeduction { get; set; }
        public double interest { get; set; }
        public double dividend { get; set; }
        public double shortTermGains { get; set; }
        public double longTermGains { get; set; }
    }





我尝试过:





What I have tried:

public static void UpdateTaxBucket(List<TaxBucket> lsttaxbucket, int year, int portnum, string mainitem, string subitem, double value)
       {
           foreach (var bucket in lsttaxbucket.Where(b => b.Year == year))
           {
               foreach (var item in bucket.taxbucketsub.Where(p => p.PortfolioID == portnum))
               {
                   switch (mainitem)
                   {
                       case "buckets":
                           switch (subitem)
                           {
                               case "Interest":
                                   item.buckets.interest = 12;
                                   break;
                               case "Dividend":
                                   item.buckets.dividend =25;
                                   break;
                               case "Short":
                                   item.buckets.shortTermGains = 30;
                                   break;
                               case "Long":
                                   item.buckets.longTermGains =35;
                                   break;
                               case "Tax":
                                   item.buckets.taxDeduction = 50;
                                   break;
                               default:
                                   break;
                           }
                           break;

推荐答案

首先从调试器开始,看看到底发生了什么 - 最有可能的,其中一个Where条件是返回空枚举。

我们不能为您执行此操作:我们无法访问您的数据!
So start with the debugger and see exactly what is going on - most likely, one of the Where conditions is returning an empty enumeration.
We can't do that for you: we don't have access to your data!


这篇关于无法更新列表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆