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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.