C
C#2y ago
azurlified

❔ 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?
ClassName objectName = new ClassName()
ClassName objectName = new ClassName()
5 Replies
mtreit
mtreit2y ago
You don't Use the var keyword
azurlified
azurlifiedOP2y ago
I see that in some cases people just write the class name instead of var, is there really any reason for doing that?
mtreit
mtreit2y ago
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
azurlified
azurlifiedOP2y ago
I see, thanks
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server