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,

Iif equivalent in C#

C# has the ? ternary operator, like other C-style languages. However, this is not perfectly equivalent to IIf(); there are two important differences. To explain the first difference, the false-part argument for this IIf() call causes a DivideByZeroException, even though the boolean argument is True. IIf() is just a function, and like all functions all … Read more

.NET Core vs Mono

What is the difference between .NET Core and Mono? I found a statement on the official site that said: “Code written for it is also portable across application stacks, such as Mono.” My goal is to use C#, LINQ, EF7 and Visual Studio to create a website that can be ran/hosted on Linux. Someone told … Read more

What is the difference between String and string in C#?

string is an alias in C# for System.String.So technically, there is no difference. It’s like int vs. System.Int32. As far as guidelines, it’s generally recommended to use string any time you’re referring to an object. e.g. Likewise, I think it’s generally recommended to use String if you need to refer specifically to the class. e.g. This is the style that Microsoft tends to use … Read more

Playing a MP3 file in a WinForm application

The link below, gives a very good tutorial, about playing mp3 files from a windows form with c#: http://www.daniweb.com/software-development/csharp/threads/292695/playing-mp3-in-c This link will lead you to a topic, which contains a lot information about how to play an mp3 song, using Windows forms. It also contains a lot of other projects, trying to achieve the same … Read more

How do you do a deep copy of an object in .NET? 

Important Note BinaryFormatter has been deprecated, and will no longer be available in .NET after November 2023. See BinaryFormatter Obsoletion Strategy I’ve seen a few different approaches to this, but I use a generic utility method as such: Notes: Your class MUST be marked as [Serializable] for this to work. Your source file must include the following code: using … Read more

How can I generate random alphanumeric strings?

I heard LINQ is the new black, so here’s my attempt using LINQ: (Note: The use of the Random class makes this unsuitable for anything security related, such as creating passwords or tokens. Use the RNGCryptoServiceProvider class if you need a strong random number generator.)

What is a “first chance exception”?

It’s a debugging concept. Basically exceptions are thrown to the debugger first and then to the actual program where if it isn’t handled it gets thrown to the debugger a second time, giving you a chance to do something with it in your IDE before and after the application itself. This appears to be a Microsoft Visual Studio invention.

Consider app.config remapping of assembly with no app.config mapping

How can I determine where to fix this reference without adding a binding to the app.config? You can try to change the “MSBuild project build output verbosity” to “Detailed” or above to check the detail error log. To do this by Tools -> Options…->Projects and Solutions->Build and Run. Set the MSBuild project build output verbosity level to Detailed or above. … Read more