0

Hey,
I noticed that I have been using var instead of string, int etc. in delegates due to a habit from another language where they were cleared after, and it just makes a temporary value for the class only, and once it has executed, is deleted.
Is this the same in C#, or can I just use string or int etc?
Which is better?
Thanks.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by bbman
0

There are arguments that go on forever and a day about when to use var...

Var can be used to signify any object but it will keep that object type once something has been assigned to it, until it falls out of scope.

There isn't a problem with using var, but make sure you name your variables to signify what the variable is (you should do this anyway, but this time especially so)

Also, all objects, once out of scope are deleted, whether they're declared var or not.

0

Okay, thanks for clearing it up. It was GameMaker where only var was cleared, but that's not really a programming language.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.