Technically, one difference is that when creating IDisposable objects, you should use new , as nyinyithann already explained. Another difference is that when creating a generic type, you can omit type arguments:
// Works and creates Dictionary<int, string> let r1 = System.Collections.Generic.Dictionary 10 r1.Add(10, "A") // You get a compiler error when you write this: let r2 = new System.Collections.Generic.Dictionary 10 r2.Add(10, "A")
Apart from these two things, there is no technical difference (and, of course, there is no difference in the generated IL when you write or omit new ).
Which one should be used when? This is a matter of style. This does not apply to F # coding standards, so it depends on your preference. Now that I think about it, I probably don't have the most consistent style. I think that I usually use new when creating instances that will be assigned values ββwith let :
let rnd = new Random()
However, I usually do not use new when creating objects that will be used as arguments (for example, Size or Point in the following example):
let frm = new Form(Size = Size(600, 400)) let gr = frm.CreateGraphics() gr.FillRectangle(Brushes.Red, Rectangle(Point(0, 0), Point(100, 100)))
Perhaps I also prefer to use new for more complex types and avoid it for simple types or for .NET value types (but I don't think I'm doing this too consistently).
source share