c# - Looping as an expression -
i come across things useful rather often, , if exists want know it. i'm not sure how explain search it, it's 1 line loop statement- similar lambada. isn't best example (it's simple solution without this), it's on mind when decided ask question. kind of thing i'm talking about.
(the following i'm thinking of looks like. i'm asking if similar exists)
in current situation, converting string byte array write stream. want able create byte array:
byte[] data = string ==> (int i; convert.tobyte(string[i]))
where number in string based on it's length, , next line output item.
you should read linq.
your code can written as:
var string = "some string"; byte[] data = string.select(x => convert.tobyte(x)).toarray();
or method group:
byte[] data = string.select(convert.tobyte).toarray();
Comments
Post a Comment