Passing just a type as a parameter in C#

There are two common approaches. First, you can pass System.Type This would be called like: int val = (int)GetColumnValue(columnName, typeof(int)); The other option would be to use generics: This has the advantage of avoiding the boxing and providing some type safety, and would be called like: int val = GetColumnValue<int>(columnName);

Member ‘‘ cannot be accessed with an instance reference

In C#, unlike VB.NET and Java, you can’t access static members with instance syntax. You should do: to refer to that property or remove the static modifier from Property1 (which is what you probably want to do). For a conceptual idea about what static is, see my other answer.

IEnumerable vs List – What to Use? How do they work?

IEnumerable describes behavior, while List is an implementation of that behavior. When you use IEnumerable, you give the compiler a chance to defer work until later, possibly optimizing along the way. If you use ToList() you force the compiler to reify the results right away. Whenever I’m “stacking” LINQ expressions, I use IEnumerable, because by … Read more

Are 2 dimensional Lists possible in c#?

Well you certainly can use a List<List<string>> where you’d then write: But why would you do that instead of building your own class to represent a track, with Track ID, Name, Artist, Album, Play Count and Skip Count properties? Then just have a List<Track>.

Reading CSV file and storing values into an array

I am trying to read a *.csv-file. The *.csv-file consist of two columns separated by semicolon (“;“). I am able to read the *.csv-file using StreamReader and able to separate each line by using the Split() function. I want to store each column into a separate array and then display it. Is it possible to … Read more

Read and parse a Json File in C#

I have spent the best part of two days “faffing” about with code samples and etc., trying to read a very large JSON file into an array in c# so I can later split it up into a 2d array for processing. The problem I was having was I could not find any examples of … Read more

How to make an HTTP POST web request

There are several ways to perform HTTP GET and POST requests: Method A: HttpClient (Preferred) Available in: .NET Framework 4.5+, .NET Standard 1.1+, .NET Core 1.0+ . It is currently the preferred approach, and is asynchronous and high performance. Use the built-in version in most cases, but for very old platforms there is a NuGet package. Setup It is recommended to instantiate one HttpClient for your application’s … Read more