❔ when instancing a class, why do you need to write the class name twice?
This just seems sort of redundant to me, is there a reason?
5 Replies
You don't
Use the var keyword
I see that in some cases people just write the class name instead of var, is there really any reason for doing that?
Or use new() on the right hand side
Some people believe using var makes it less obvious what the type actually is. For instance:
var x = GetTheThing();
What is the type of x? Not clear from the code alone.
You also can't use var in field declarations
For instance
So it depends on the exact scenario
I generally use var where possible
I see, thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.