How can I call this constructor ?
public class DataField
{
public String Name;
public Type TheType;
public DataField(string name, Type T)
{
Name = name;
TheType = T;
}
}
I thought of
f = new DataField("Name",typeof(new String()));
but I want to avoid object creation. So is this one ok ?
f = new DataField("Name",String);
Both values and references are stored in the stack memory. Arguments in Java are always passed-by-value. During method invocation, a copy of each argument, whether its a value or reference, is created in stack memory which is then passed to the method.
The basic data types can be passed as arguments to the C# methods in the same way the object can also be passed as an argument to a method. But keep in mind that we cannot pass a class object directly in the method. We can only pass the reference to the object in the method.
Method signaturepublic static void myMethod(String fname) ; The method takes the String parameter and then appends additional text to the string and then outputs the value to the console. The method is invoked from the method by passing some sample strings with male names.
You can use a type name with typeof
:
f = new DataField("Name", typeof(string));
You should be able to use simply typeof(string)
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