Cannot declare instance members in a static class in C#

If the class is declared static, all of the members must be static too. Are you sure you want your employee class to be static? You almost certainly don’t want that behaviour. You’d probably be better off removing the static constraint from the class and the members.

Categories c# Tags

Delay function in C#

Use an async method to create a delay using the built-in Task.Delay method. This will cause execution to be paused and then resumed after the specified time without blocking the current thread. In your specific case

Best way to randomize an array with .NET

If you’re on .NET 3.5, you can use the following IEnumerable coolness: Edit: and here’s the corresponding VB.NET code: Second edit, in response to remarks that System.Random “isn’t threadsafe” and “only suitable for toy apps” due to returning a time-based sequence: as used in my example, Random() is perfectly thread-safe, unless you’re allowing the routine … Read more

LINQ query on a DataTable

You can’t query against the DataTable‘s Rows collection, since DataRowCollection doesn’t implement IEnumerable<T>. You need to use the AsEnumerable() extension for DataTable. Like so: And as @Keith says, you’ll need to add a reference to System.Data.DataSetExtensions AsEnumerable() returns IEnumerable<DataRow>. If you need to convert IEnumerable<DataRow> to a DataTable, use the CopyToDataTable() extension. Below is query with Lambda Expression,

Quickest way to compare two generic lists for differences

Use Except: I suspect there are approaches which would actually be marginally faster than this, but even this will be vastly faster than your O(N * M) approach. If you want to combine these, you could create a method with the above and then a return statement: One point to note is that there is … Read more

Get local IP address

To get local Ip Address: To check if you’re connected or not: System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

Convert an array to string

You can join your array using the following: Then you can output anyway you want. You can change the comma to what ever you want, a space, a pipe, or whatever.