如何使用基类属性 [英] How to use the base class properties

查看:97
本文介绍了如何使用基类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我在哪里做错了,我尝试了很多次,但这个代码有问题,在更新方法中我正在设置id,版本和设置值,这些属性都在logodetails类中,我正在使用logodetails作为图像细节的基类。当我在项目的其他地方使用ImageDetails类时,我得到的值为0; (id = 0,version = 0,set = 0)



I don't know where I am doing mistake, I tried lot times, but somthing wrong with this code, In updates method I am geting id, version and set values, those properties are in logodetails class, and I am using logodetails as a base class to image details. when iam using ImageDetails class in other place in the project I am getting the values 0 ; (id = 0, version =0, set = 0)

public void Updates(AUnit _aUnit, int Id)
{
    ImageDetails _details = new ImageDetails(_aUnit, Id);
    List<LogoDetails> logolist = new List<LogoDetails>(); 
    LogoDetails logoDetails = new LogoDetails();

    int count = (int) _aUnit.ReadBits(8);
    for (int i = 0; i < (int) count; i++)
    {
        logoDetails.ID = 15;(int) _aUnit.ReadBits(8);
        logoDetails.Version = 6; (int) _aUnit.ReadBits(8);
        logoDetails.set = 14; (int) _aUnit.ReadBits(24);
        logolist.Add(logoDetails);
    }
    foreach (LogoDetails listitem in logolist)
    {
        _details.Rset = _aUnit.Buffer.Skip(10).Take(_details.set).ToArray();
    }
}

public class ImageDetails :LogoDetails
{
    public ImageDetails(AUnit _au, int carouselId)
    {            
        carId = carouselId;
        _AUnit = _au;         

        _updateTime = "";
    }
    private string _updateTime;

    public string UpdateTime
    {
        get { return _updateTime; }
        set { _updateTime = value; }
    }
}

public class LogoDetails
{
    public int LogoID { get; set; }
    public int LogoVersion { get; set; }
    public int Offset { get; set; }
}





我尝试过:



我尝试使用相同的类,而不是使用基类,它像这样工作



What I have tried:

I tried using the same class, instead of using base class, it worked like this

推荐答案

public void Updates(AUnit _aUnit, int Id)
{
    ImageDetails _details = new ImageDetails(_aUnit, Id);  // new object
    List<LogoDetails> logolist = new List<LogoDetails>();  // new object
    LogoDetails logoDetails = new LogoDetails();           // new object
 
    int count = (int) _aUnit.ReadBits(8);
    for (int i = 0; i < (int) count; i++)
    {
        logoDetails.ID = 15;(int) _aUnit.ReadBits(8);
        logoDetails.Version = 6; (int) _aUnit.ReadBits(8);
        logoDetails.set = 14; (int) _aUnit.ReadBits(24);
        logolist.Add(logoDetails);
    }
    foreach (LogoDetails listitem in logolist)
    {
        _details.Rset = _aUnit.Buffer.Skip(10).Take(_details.set).ToArray();
    }
}



您可以在此方法中创建三个新对象,但不要将它们保存在任何位置。因此,一旦方法结束,对象就会超出范围,它们及其内容将再也不会被看到。


You create three new objects inside this method, but you do not save them anywhere. So as soon as the method ends the objects go out of scope and they, and their contents, are never seen again.


这篇关于如何使用基类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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