Problem with properties

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
got such proble (easy I think:( )

i declare variable:
private int[] var1 = new int[10];

how to write property for this variable?
 
Hi Damar,

Do you mean something like this?

public int[] MyProperty
{
get
{
return var1;
}
set
{
var1 = value;
}
}


Hello
got such proble (easy I think:( )

i declare variable:
private int[] var1 = new int[10];

how to write property for this variable?
 
Yeah thanks.
I would not suppose its so easy.
I tried with indexers, but your solution is simpler

Morten Wennevik said:
Hi Damar,

Do you mean something like this?

public int[] MyProperty
{
get
{
return var1;
}
set
{
var1 = value;
}
}


Hello
got such proble (easy I think:( )

i declare variable:
private int[] var1 = new int[10];

how to write property for this variable?
 
Hi DAMAR,

Morten's solutions is easy, and it works with
simplest possible way.
Remember, that *MyProperty* property will return
and set only a "reference" to table of *int*.
e.g.:

int[] intTable=myObj.MyProperty;
intTable[2]=13;
// myObj.MyProperty[2]==13

So if you want to keep table *MyProperty* as
an independent table of int's then you should
extend *get;set* code with Array.Copy(ing).

HTH
Marcin
Yeah thanks.
I would not suppose its so easy.
I tried with indexers, but your solution is simpler

:

Hi Damar,

Do you mean something like this?

public int[] MyProperty
{
get
{
return var1;
}
set
{
var1 = value;
}
}


Hello
got such proble (easy I think:( )

i declare variable:
private int[] var1 = new int[10];

how to write property for this variable?
 
would u help me how to write it? ArrayCopy?

Marcin Grzębski said:
Hi DAMAR,

Morten's solutions is easy, and it works with
simplest possible way.
Remember, that *MyProperty* property will return
and set only a "reference" to table of *int*.
e.g.:

int[] intTable=myObj.MyProperty;
intTable[2]=13;
// myObj.MyProperty[2]==13

So if you want to keep table *MyProperty* as
an independent table of int's then you should
extend *get;set* code with Array.Copy(ing).

HTH
Marcin
Yeah thanks.
I would not suppose its so easy.
I tried with indexers, but your solution is simpler

:

Hi Damar,

Do you mean something like this?

public int[] MyProperty
{
get
{
return var1;
}
set
{
var1 = value;
}
}


On Mon, 10 Jan 2005 02:29:01 -0800, DAMAR


Hello
got such proble (easy I think:( )

i declare variable:
private int[] var1 = new int[10];

how to write property for this variable?
 
It would be something like this

private int[] myints;

public int[] MyProperty
{
get
{
int[] temparray = new int[myints.Length];
Array.Copy(myints, temparray, myints.Length);
return temparray;
}
set
{
myints = new int[value.Length];
Array.Copy(value, myints, value.Length);
}
}


would u help me how to write it? ArrayCopy?

Marcin Grzębski said:
Hi DAMAR,

Morten's solutions is easy, and it works with
simplest possible way.
Remember, that *MyProperty* property will return
and set only a "reference" to table of *int*.
e.g.:

int[] intTable=myObj.MyProperty;
intTable[2]=13;
// myObj.MyProperty[2]==13

So if you want to keep table *MyProperty* as
an independent table of int's then you should
extend *get;set* code with Array.Copy(ing).

HTH
Marcin
Yeah thanks.
I would not suppose its so easy.
I tried with indexers, but your solution is simpler

:


Hi Damar,

Do you mean something like this?

public int[] MyProperty
{
get
{
return var1;
}
set
{
var1 = value;
}
}


On Mon, 10 Jan 2005 02:29:01 -0800, DAMAR


Hello
got such proble (easy I think:( )

i declare variable:
private int[] var1 = new int[10];

how to write property for this variable?
 
Back
Top