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

1
The Beautiful Web
Jens Oliver Meiert 2 votes
3
LLM Use in the Python Source Code
Miguel Grinberg 1 votes
4
Wagon’s algorithm in Python
John D. Cook 1 votes