473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with properties

Hello
got such proble (easy I think:( )

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

how to write property for this variable?

Nov 16 '05 #1
5 938
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
<DA***@discussions.microsoft.com> wrote:
Hello
got such proble (easy I think:( )

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

how to write property for this variable?


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Yeah thanks.
I would not suppose its so easy.
I tried with indexers, but your solution is simpler

"Morten Wennevik" wrote:
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
<DA***@discussions.microsoft.com> wrote:
Hello
got such proble (easy I think:( )

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

how to write property for this variable?


--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3
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

"Morten Wennevik" wrote:

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
<DA***@discussions.microsoft.com> wrote:

Hello
got such proble (easy I think:( )

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

how to write property for this variable?


--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #4
would u help me how to write it? ArrayCopy?

"Marcin Grzębski" wrote:
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

"Morten Wennevik" wrote:

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
<DA***@discussions.microsoft.com> wrote:
Hello
got such proble (easy I think:( )

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

how to write property for this variable?


--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #5
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);
}
}
On Thu, 13 Jan 2005 02:35:03 -0800, DAMAR
<DA***@discussions.microsoft.com> wrote:
would u help me how to write it? ArrayCopy?

"Marcin Grzębski" wrote:
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
>
> "Morten Wennevik" wrote:
>
>
>>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
>><DA***@discussions.microsoft.com> wrote:
>>
>>
>>>Hello
>>>got such proble (easy I think:( )
>>>
>>>i declare variable:
>>>private int[] var1 = new int[10];
>>>
>>>how to write property for this variable?
>>>
>>>
>>>
>>
>>
>>
>>--
>>Happy Coding!
>>Morten Wennevik [C# MVP]
>>


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mevar81 | last post by:
Hi to everybody.I have a problem with the PropertyGrid control.I want to display not all the properties of a generic Control(Button,TextBox,ComboBox,ecc.).In general I don't want to display only...
11
by: wASP | last post by:
Hi, I've got a pair of int properties in a class. The properties in question are indexing values - but that's not relevant to my problem - or it's just symptomatic ... sort of. They are...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
4
by: Marc | last post by:
So I am having some issues with code written by another developer that interfaces with Active Directory. We had a catastrophic failure on the server and had to recreate the AD. No the following...
0
by: Tim::.. | last post by:
Hi... I'm having a big problem with a datagrid that obtains data from 2 different locations... Active Directory and SQL Database The data is inserted into a datatable and the sorted by a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.