Steven Giesel 4/13/2022

default(MyStruct) vs new MyStruct() - what is the difference?

Read Original

This technical article details a key difference in C# 10 between using the `default` operator and the `new` operator with structs. It explains that while `new MyStruct()` invokes a parameterless constructor (introduced in C# 10), `default(MyStruct)` does not, resulting in fields being initialized to their default values instead of any constructor logic.

default(MyStruct) vs new MyStruct() - what is the difference?

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week