My question is related to the C # function parameter I used for C ++, where the parameter is by default , Unless you explicitly specify them as a reference. So, in C #, how do I give a function parameter to pass from the value instead of the reference? Actually, I just want to pass a variable, and after calling the function I do not want to modify that variable.
Example:
void foo (widget w) {Wx = 3; // where w will not actually be modified here}
As int is a primitive data type, x has already been passed from the value in your old example.
Proof of concept:
class program {static zero main (string [] args) {int x = 1; System.Console.WriteLine (x); // 1 fu (x); System.Console.WriteLine (x); // 1} static void foo (int x) {x ++; Edit} Edit: For non-primitive data types, to answer that C # does not use copy structures like C ++, Therefore, I am not sure how to pass the actual objects to the value except for applying the interface or something to its class (for the record, C # passes the context of objects by C # value).
< P> Edit 2: An excellent, if Best, No, the way to go ... is defined as your widget type (looks like this).
Comments
Post a Comment