Thoughts on foreach with Enumerable.Range vs traditional for loop

I find the latter’s “minimum-to-maximum” format a lot clearer than Range‘s “minimum-count” style for this purpose. Also, I don’t think it’s really a good practice to make a change like this from the norm that is not faster, not shorter, not more familiar, and not obviously clearer. That said, I’m not against the idea in … Read more

System.Drawing.Image to stream C#

Try the following: public static Stream ToStream(this Image image, ImageFormat format) { var stream = new System.IO.MemoryStream(); image.Save(stream, format); stream.Position = 0; return stream; } Then you can use the following: var stream = myImage.ToStream(ImageFormat.Gif); Replace GIF with whatever format is appropriate for your scenario.

How to dynamic new Anonymous Class?

Anonymous types are just regular types that are implicitly declared. They have little to do with dynamic. Now, if you were to use an ExpandoObject and reference it through a dynamic variable, you could add or remove fields on the fly. edit Sure you can: just cast it to IDictionary<string, object>. Then you can use … Read more

Why must a lambda expression be cast when supplied as a plain Delegate parameter

A lambda expression can either be converted to a delegate type or an expression tree – but it has to know which delegate type. Just knowing the signature isn’t enough. For instance, suppose I have: public delegate void Action1(); public delegate void Action2(); … Delegate x = () => Console.WriteLine(“hi”); What would you expect the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)