Both seem to return the same type, and have the same signature.
So what is the difference between them, and when should we use each?
A variable is the way in which an attribute or quantity is represented. A parameter is normally a constant in an equation describing a model (a simulation used to reproduce behavior of a system).
A variable in SQL is an object that can hold a single data value of a specific type. In contrast, a parameter in SQL is an object that can exchange data between stored procedures and functions.
Parameter(Type, String) Creates a ParameterExpression node that can be used to identify a parameter or a variable in an expression tree. Parameter(Type) Creates a ParameterExpression node that can be used to identify a parameter or a variable in an expression tree.
There is a clear difference between variables and parameters. A variable represents a model state, and may change during simulation. A parameter is commonly used to describe objects statically. A parameter is normally a constant in a single simulation, and is changed only when you need to adjust your model behavior.
Effectively, there is no difference, apart from the fact that Variable()
does not allow ref
types. To see that, you can look at the reference source:
public static ParameterExpression Parameter(Type type, string name) {
ContractUtils.RequiresNotNull(type, "type");
if (type == typeof(void)) {
throw Error.ArgumentCannotBeOfTypeVoid();
}
bool byref = type.IsByRef;
if (byref) {
type = type.GetElementType();
}
return ParameterExpression.Make(type, name, byref);
}
public static ParameterExpression Variable(Type type, string name) {
ContractUtils.RequiresNotNull(type, "type");
if (type == typeof(void)) throw Error.ArgumentCannotBeOfTypeVoid();
if (type.IsByRef) throw Error.TypeMustNotBeByRef();
return ParameterExpression.Make(type, name, false);
}
As you can see, both methods call ParameterExpression.Make()
, so the returned object will behave the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With