Assigning Values RRS feed

  • Question

  • Hi everyone,

    I'd like to know how to assign more than one value to a value without each value equaling each other.

    For example:

    a = b  and  a = c   and  a=d   but b does not equal c or d and c does not equal d. Can someone help?

    Sunday, June 22, 2008 1:42 PM


  • What you want is mathematically impossible, but maybe you're asking the wrong question. Perhaps you need 'a' to be a collection; that way it can have multiple values. Like so:

    List<int> a = new List<int>(); 

    Or you can use a hashtable / dictionary to use a lookup by name:

    int b, c, d; 
    Dictionary<stringint> a = new Dictionary<stringint>(); 
    a["b"] = b; 
    a["c"] = c; 
    a["d"] = d; 

    Or maybe what you need is to access b, c and d through a in a type safe manner:

    class A 
       public int B { getset; } 
       public int C { getset; } 
       public int D { getset; } 
    A a = new A { B = 1, C = 2, D = 3 }; 
    // Now you can access b, c and d through a. 
    int x = a.B + a.C + a.D; 

    I hope this helps.
    • Marked as answer by jack 321 Wednesday, June 25, 2008 6:27 AM
    Sunday, June 22, 2008 2:27 PM