Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, In Update method I had int count, let say count == 4, then i am using for loop to get id, version and set. In this case Id,version and set values getting only the last value, but how to get the all the values

public void Updates(AUnit _aUnit, int Id)
    {
        ImageDetails _details = new ImageDetails(_aUnit, Id);

        int count = (int) _aUnit.ReadBits(8);
        for (int i = 0; i < (int) count; i++)
        {
            _details.ID = (int) _aUnit.ReadBits(8);
            _details.Version = (int) _aUnit.ReadBits(8);
            _details.set = (int) _aUnit.ReadBits(24);
        }

        _details.Rset = _aUnit.Buffer.Skip(10).Take(_details.set).ToArray();

        //MemoryStream ms = new MemoryStream(_details.PortrateImages.First());
        //Image image = Image.FromStream(ms);
        //Bitmap bmp = new Bitmap(image);

        _details.UpdateTime = DateTime.Now.ToString("h:mm:ss tt");
        newData.Add(_details);
    }
public class ImageDetails
  {
    public ImageDetails(AUnit _au, int carouselId)
    {            
        carId = carouselId;
        _AUnit = _au;         

        _updateTime = "";
    }
    private string _updateTime;
    public int ID { get; set; }
    public int Version { get; set; }
    public int set { get; set; }
    public int carId { get; set; }
    public byte[] Rset { get; set; }
    public AUnit _AUnit { get; set; }
    public byte[] bytes { get; set; }
    public List<byte[]> dataArray = new List<byte[]>();

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

    public List<byte[]> PImages
    {
        get
        {
            List<byte[]> Plogos = new List<byte[]>();
            if (carId == 2)
            {
                Plogos.Add(Rset);
            }
            return Plogos;
        }

    }
    public List<byte[]> LImages
    {
        get
        {
            List<byte[]> Llogos = new List<byte[]>();
            if (carId == 1)
            {
                Llogos.Add(Rset);
            }

            return Llogos;
        }

    }
}


What I have tried:

I tried but i feel its wrong and not working, Created a seperate list for id, version and set, eg: _details.imageList.Add(logoHeader.LogoID);
Posted
Updated 29-Jun-17 20:41pm
Comments
F-ES Sitecore 30-Jun-17 4:33am    
Use the debugger to step through your code and it should be obvious what is happening.

1 solution

Try the following :
C#
#
public void Updates(AUnit _aUnit, int Id)
    {
 
        int count = (int) _aUnit.ReadBits(8);
        for (int i = 0; i < (int) count; i++)
        {
            ImageDetails _details = new ImageDetails(_aUnit, Id);
            _details.ID = (int) _aUnit.ReadBits(8);
            _details.Version = (int) _aUnit.ReadBits(8);
            _details.set = (int) _aUnit.ReadBits(24);
            newData.Add(_details);
        }
 
        _details.Rset = _aUnit.Buffer.Skip(10).Take(_details.set).ToArray();
 
        //MemoryStream ms = new MemoryStream(_details.PortrateImages.First());
        //Image image = Image.FromStream(ms);
        //Bitmap bmp = new Bitmap(image);
 
        _details.UpdateTime = DateTime.Now.ToString("h:mm:ss tt");
    }


the difference now is that you create an entry for your collection inside the Loop and add each of those created entries to your collection (also inside the Loop)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900