|
-
Jul 7th, 2011, 01:17 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Remove byte from bytearray.
I need to remove byte where value is 0 from a byte array.
Please help..
Code:
byte[] newArray = oldArray.Where(b => b != 0xff).ToArray();
this removing the first position,
Visual Studio.net 2010
If this post is useful, rate it

-
Jul 7th, 2011, 04:22 AM
#2
Re: Remove byte from bytearray.
If you want to remove elements where the value is equal to 0 then why are you telling it to remove elements where the value is not equal to 255?
-
Jul 7th, 2011, 04:31 AM
#3
Re: Remove byte from bytearray.
The code you show filters the old array for all values that are not equal to 255 (0xff).
If you want to filter out 0's use b => b != 0.
Edit, oops bit slow (got carried away playing with lambda)
-
Jul 7th, 2011, 04:43 AM
#4
Thread Starter
Fanatic Member
Re: Remove byte from bytearray.
 Originally Posted by jmcilhinney
If you want to remove elements where the value is equal to 0 then why are you telling it to remove elements where the value is not equal to 255?
No, actually i don't know the meaning of that code, when i surfed in net for removing byte from byte array.. i got something like above.. so that i tried and copied here..
i used RemoveAll(Predicate<T> match), its working fine.
i have to learn linq its reducing much steps..
byte[] newArray = oldArray.Where(b => b != 0).ToArray();
its simple rather than using list.
thanks milk,
Visual Studio.net 2010
If this post is useful, rate it

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|