-2

this might sound unclear but i know its difficult but we can remove specific bytes from byte[] array but if the array contain similiar values while removing values it can remove other values i m using :

        byte[] B = new byte[] { 10, 0, 0, 10 };
        byte[] D = new byte[] { 0, 0 };

        byte[] NewArray = B.Except(D).ToArray();

        BytesDisplayer.Text = String.Join(",", NewArray);

but lets say i have a byte as:

byte[] Data = new byte[] {0,10,10,10,0,5,5,5,10,10,10};

and i want to remove the last 3 values (10) My method will remove all the 10 value on that array , so basically i want to know is there is a way to remove specific bytes in specific indexes and how ?

Buffer zz
  • 5
  • 5
  • Yes, write a method that does that. – 15ee8f99-57ff-4f92-890c-b56153 Nov 06 '16 at 13:59
  • Excuse my knowldege , how ? – Buffer zz Nov 06 '16 at 14:00
  • `Array.Resize` and/or `Array.Copy`. Easiest is to convert the array to List and use the List methods http://stackoverflow.com/questions/457453/remove-element-of-a-regular-array – Slai Nov 06 '16 at 14:01
  • 2
    There will probably be a loop involved. Sit down and think through what the code needs to do. Solve the problem by hand with pencil and paper. Write down the steps and translate them into C#. This is called programming. If you run into any specific problems making your code work, and you can't find a solution even though you try to find one yourself, ask for help here. We all did this when we were younger. You can do it to. – 15ee8f99-57ff-4f92-890c-b56153 Nov 06 '16 at 14:01
  • @EdPlunkett Thanks sir! – Buffer zz Nov 06 '16 at 14:06

1 Answers1

0

try this:

byte[] Data = new byte[] { 0, 10, 10, 10, 0, 5, 5, 5, 10, 10, 10 };
 Data =  Data.Where((item, index) => index < 8).ToArray();
James
  • 729
  • 6
  • 10