.NET C# Question

Soldato
Joined
7 Jun 2005
Posts
3,035
Location
SE London
Hey, i've created a basic get/set property method for one of my usercontrols, which takes an integer array in as a parameter, or returns it, like so:

Code:
public int[] Value
{
        get
        {
            .........
         }
         set
         {
            ..........
          }
}

Now i have another page where i'm using this control, and i'm having the following piece of code in my Page_Load event:

Code:
        int[] mySelectedValues = new int[2];
        mySelectedValues[0] = 9;
        mySelectedValues[1] = 8;

        msTitles.Value = mySelectedValues;

when debuggin, at the last line of the above code, the variable "mySelectedValues" has become a 2-dimensional array (with values 8 and 9), but when stepping into the .Value property set/get method, no value has been passed through.

Any ideas anyone?
 
The original code I had for the Value property/method:
Code:
public int[] Value
    {
        get
        {
            int[] myIntArray = new int[lbSelectedValues.Items.Count];

            for (int x = 0; x < lbSelectedValues.Items.Count; x++)
            {
                myIntArray[x] = Int32.Parse(lbSelectedValues.Items[x].Value);
            }

            return myIntArray;     
        }

        /*set
        {
            this.arrInitialValues = Value;
        }*/
    }

the "get" method works fine, however for the "set" method i had to write a separate method as this didn't work.

the following method worked fine:

Code:
public void setValue(int[] Value)
    {
        this.arrInitialValues = Value;
    }


WHat's the Difference?

p.s. yes i know about debugging, i actually "step into" the method and can see that the initial array has not been passed in...
 
No it's not that, the code is now commented out and probably the s deleted by accident. there were not compilation errors when i executed the code.
 
Thanks - that was it! My code works fine now, as following:

Code:
public int[] Value
    {
        get
        {
            int[] myIntArray = new int[lbSelectedValues.Items.Count];

            for (int x = 0; x < lbSelectedValues.Items.Count; x++)
            {
                myIntArray[x] = Int32.Parse(lbSelectedValues.Items[x].Value);
            }

            return myIntArray;     
        }

        set
        {
            this.arrInitialValues = value;
        }
    }

and the code that calls the .Value code above:

Code:
int[] mySelectedValues = new int[2];
mySelectedValues[0] = 9;
mySelectedValues[1] = 8;
msTitles.Value = mySelectedValues;

MANY THANKS GUYS!
 
i think my reasoning was to have .Value as most other .net objects have .Value, so to keep method names similar. Yes, the intrinsic "value" property is confusing.
 
Back
Top Bottom