Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • @xanatos why do you use var type?
    – Alex
    Commented Apr 9, 2013 at 11:30
  • 7
    @Alex This is C#, not Javascript. var isn't a type. It's an abbreviation for "the type of the right-hand expression" (so string) (see for example stackoverflow.com/questions/41479/use-of-var-keyword-in-c-sharp )
    – xanatos
    Commented Apr 9, 2013 at 13:21
  • 3
    @xanatos, @alex technically var in JavaScript is not a type like you're saying. var in JavaScript is a keyword meaning I'm wanting to declare a variable here which type is inferred later.
    – sabotero
    Commented Nov 22, 2013 at 10:53
  • I had to use Encoding.ASCII.GetString instead of Encoding.Unicode.GetString in my case to get it to work.
    – SNag
    Commented Jan 7, 2016 at 17:43
  • 1
    @SNag, avoid usages of ASCII, this is only for the last resort, when you are absolutely known what are you doing and why. 1) By default first thing to play with must be UTF8 encoding 2) If for some reason you are dealing with an old non-unicode data you can try Encoding.Default 3) Only as a fallback if you explicitly going to stick with 0-127 byte values range and Latin chars only you can try ASCII (7bit that fits into 8bit) In the author's case it is clear that data is UTF16 encoded and this is why Encoding.Unicode is correct here. This is mostly used by inmemory blobs. Commented May 16, 2018 at 10:19