How do you get the index of the current iteration of a foreach loop?

Ian Mercer posted a similar solution as this on Phil Haack’s blog: This gets you the item (item.value) and its index (item.i) by using this overload of LINQ’s Select: the second parameter of the function [inside Select] represents the index of the source element. The new { i, value } is creating a new anonymous object. Heap allocations can be avoided … Read more

Recommendation for C# Matrix Library

Math.NET Numerics is very nice, if it supports the operations you want. The older Math.Net Iridium still supports more options. Also, dnAnalytics is quite nice, but no longer being developed. (It, as well as Iridium, are being merged into Math.NET Numerics.) On the commercial side, there are some very good, robust options. The Extreme Optimization Numerical Libraries work very well. … Read more

Why should I use IHttpActionResult instead of HttpResponseMessage?

You might decide not to use IHttpActionResult because your existing code builds a HttpResponseMessage that doesn’t fit one of the canned responses. You can however adapt HttpResponseMessage to IHttpActionResult using the canned response of ResponseMessage. It took me a while to figure this out, so I wanted to post it showing that you don’t necesarily have to choose one or the other: Note, ResponseMessage is a … Read more

Parse Json string in C#

I’m using Json.net in my project and it works great. In you case, you can do this to parse your json: EDIT: I changed the code so it supports reading your json file (array) Code to parse: Output: BTW, you can use LinqPad to test your code, easier than creating a solution or project in … Read more

What represents a double in sql server?

Or if you want to go old-school: You can also use float(53), but it means the same thing as float. (“real” is equivalent to float(24), not float/float(53).) The decimal(x,y) SQL Server type is for when you want exact decimal numbers rather than floating point (which can be approximations). This is in contrast to the C# “decimal” data type, which … Read more