C# Append byte array to existing file

One way would be to create a FileStream with the FileMode.Append creation mode. Opens the file if it exists and seeks to the end of the file, or creates a new file. This would look something like: public static void AppendAllBytes(string path, byte[] bytes) { //argument-checking here. using (var stream = new FileStream(path, FileMode.Append)) { … Read more

Java ‘+’ operator between Arithmetic Add & String concatenation? [duplicate]

This is basic operator precedence, combined with String concatenation vs numerical addition. Quoting: If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run time. The result of string concatenation is a reference to a String object that is the concatenation … Read more

How to concatenate two IEnumerable into a new IEnumerable?

Yes, LINQ to Objects supports this with Enumerable.Concat: var together = first.Concat(second); NB: Should first or second be null you would receive a ArgumentNullException. To avoid this & treat nulls as you would an empty set, use the null coalescing operator like so: var together = (first ?? Enumerable.Empty<string>()).Concat(second ?? Enumerable.Empty<string>()); //amending `<string>` to the … Read more

How to concatenate two dictionaries to create a new one? [duplicate]

Slowest and doesn’t work in Python3: concatenate the items and call dict on the resulting list: $ python -mtimeit -s’d1={1:2,3:4}; d2={5:6,7:9}; d3={10:8,13:22}’ \ ‘d4 = dict(d1.items() + d2.items() + d3.items())’ 100000 loops, best of 3: 4.93 usec per loop Fastest: exploit the dict constructor to the hilt, then one update: $ python -mtimeit -s’d1={1:2,3:4}; d2={5:6,7:9}; … Read more