Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Passing variables in a constructor [modified]

Passing variables in a constructor [modified]

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MAW30
    wrote on last edited by
    #1

    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

    P J M 3 Replies Last reply
    0
    • M MAW30

      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

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M MAW30

        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

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M MAW30

          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

          M Offline
          M Offline
          Maharishi Bhatia
          wrote on last edited by
          #4

          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. Maharishi

          Nothing is Impossible. Even impossible spells "i m possible"

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups