Hi Jon,
Can someone please give me a brief explaination how each of the following
differs?
long lVariable; //Variable name and type.
"long" is a type declaration. It defines the type of data the variable will
hold.
"1Variable" is an illegal variable name (you can't begin a variable name
with a number). A variable name is a reference to the data it holds. For
example, you are a person. Your name is "Jon." When I refer to you as "Jon"
I am not referring to your name, but to you. The same is true for variables.
Of course, variables must have unique names. If, for example, there were 2
Jons in the
room, I would have to use some modifier to specify which one I was referring
to. Variables don't have such modifiers, so the name must be unique within
the context of the scope that the variable exists in.
//How do the following methods differ???
1) (string)lVariable;
Casting. This indicates that the variable should be cast (treated as) a
string. Casting and converting are different. Converting is the use of a
method to return an object of the new type. Casting is simply treating the
object temporarily as if it were of a different type. In the above
reference, no new object is created.
2) Convert.ToString(lVariable);
This is an example of converting. The method returns a string, having a
string value of the variable.
This is another conversion technique. It is simply a different method.
I'm not sure what this is. It is a method that returns a string, but you
didn't specify the class to which the method belongs. In any case, it is not
strictly a conversion, but a method that returns a string, which is somehow
derived from the variable. For example, a conversion can only return a
string representation of the object. A method can use the object and perform
any desired processing, to return a string, which may or may not be a string
represntation of the object.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition