Passing variables in a constructor [modified]
-
Is there a way for me to pass multiple variables in a constructor with a single variable, why because I will be repeating this process many time. Also have a definition for the constructor variables. See the following example: PassVariables = {a, b, c) ConstructorVariables = {this.A a, this.B b, this.C c) Thanks in advance, Michael -- modified at 22:01 Wednesday 28th November, 2007
-
Is there a way for me to pass multiple variables in a constructor with a single variable, why because I will be repeating this process many time. Also have a definition for the constructor variables. See the following example: PassVariables = {a, b, c) ConstructorVariables = {this.A a, this.B b, this.C c) Thanks in advance, Michael -- modified at 22:01 Wednesday 28th November, 2007
You could have all of the variables you want to pass inside an object that you pass through the constructor. There are many ways this can be done.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Is there a way for me to pass multiple variables in a constructor with a single variable, why because I will be repeating this process many time. Also have a definition for the constructor variables. See the following example: PassVariables = {a, b, c) ConstructorVariables = {this.A a, this.B b, this.C c) Thanks in advance, Michael -- modified at 22:01 Wednesday 28th November, 2007
In addition to what Paul said, you can also pass in an array:
class Foo
{
Foo(string[] variables)
{
this.A = variables[0];
this.B = variables[1];
...
}
}Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Story of the Spoiled Child The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Is there a way for me to pass multiple variables in a constructor with a single variable, why because I will be repeating this process many time. Also have a definition for the constructor variables. See the following example: PassVariables = {a, b, c) ConstructorVariables = {this.A a, this.B b, this.C c) Thanks in advance, Michael -- modified at 22:01 Wednesday 28th November, 2007
You can pass this values as parameters to the constructor also
public class Foo{ string a1, b1; Foo(string A, string B){ a1=A; b1=B; } }
Hope this helps. MaharishiNothing is Impossible. Even impossible spells "i m possible"