将数据集中的值分配给子类的属性值

时间:2016-07-12 09:23:17

标签: c#

我有超类和子类。

double[][] input;
    double[][] output;
    private void button1_Click(object sender, EventArgs e)
    {
        input = new double[][]
        {
            new double[] {0,1,2,3 },
            new double[] {9,8 },
            new double[] {14,5,0 },
            new double[] {2.0,2.3,2.5 }
        };
        output = function(input);
    }
    static double[][] function (double[][] ins)
    {
        double[][] ous = ins;
        int leng = ins.GetLength(0);
        for (int i = 0; i < leng; i++)
        {
            int lung = ins[i].GetLength(0);
            for (int j = 0; j < lung; j++)
                ous[i][j] += 14.4;
        }
        return ous;
    }

我还有另一个班级

public class Fee
{
    public decimal Dollar { get; set; }
    public decimal Percentage { get; set; }
}

public class AdminFee : Fee
{

}

我想将datarow值分配给adminFees。当我分配 值,我在运行时都得到了强制转换错误或adminfees字段空值。

public class TypeFee
{ 
    public AdminFee AdminFees { get; set;}
}

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

你有很多拼写错误和编码错误。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            TypeFee tfee = new TypeFee();
            AdminFee addfee = new AdminFee();
            tfee.adminFees = (AdminFee)addfee;
            tfee.adminFees.dollar = addfee.dollar;
        }
    }
    public class Fee
    { 
        public decimal dollar {get;set;} 
        public decimal percentage {get;set;} 
    } 
    public class AdminFee :Fee
    { }
    public class TypeFee
    { 
        public AdminFee adminFees {get;set;}
    }
}