Writing data into CSV file in C#

UPDATE Back in my naïve days, I suggested doing this manually (it was a simple solution to a simple question), however due to this becoming more and more popular, I’d recommend using the library CsvHelper that does all the safety checks, etc. CSV is way more complicated than what the question/answer suggests. Original Answer As you already … Read more

“Too many characters in character literal error”

I’m struggling with a piece of code and getting the error: Too many characters in character literal error Using C# and switch statement to iterate through a string buffer and reading tokens, but getting the error in this line: case ‘&&’: case ‘||’: case ‘==’: How can I keep the == and && as a … Read more

How to do constructor chaining in C#

You use standard syntax (using this like a method) to pick the overload, inside the class: then: Note also: you can chain to constructors on the base-type using base(…) you can put extra code into each constructor the default (if you don’t specify anything) is base() For “why?”: code reduction (always a good thing) necessary … Read more

Get int value from enum in C#

Just cast the enum, e.g. The above will work for the vast majority of enums you see in the wild, as the default underlying type for an enum is int. However, as cecilphillip points out, enums can have different underlying types. If an enum is declared as a uint, long, or ulong, it should be … Read more