473,387 Members | 1,942 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.

properties in c#

hello

I have such problem:

int[] var1 = new int[10];
how to write properties for this variable? but propoerty must contain
independent table of int's stored in var1.
This statement is not sufficient:

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

thanks

Nov 16 '05 #1
4 991
Do you mean to write an indexer?

public class WithIndexer
{

int[] vars=new int[100];

public int this[int index]
{
get{return vars[index];}
set{vars[index]=value;}
}

}

The variables can be accessed using the following...

WithIndexer x=new WithIndexer()
x[10]=5;
int y=x[10];

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"DAMAR" <DA***@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.com...
hello

I have such problem:

int[] var1 = new int[10];
how to write properties for this variable? but propoerty must contain
independent table of int's stored in var1.
This statement is not sufficient:

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

thanks

Nov 16 '05 #2
hi ya,
ok i think i kinda know what u want...the sample code you've given is a little abstract :) but...

//this is creating an Array of 10 int's, with the array name var1
int[] var1=new int[10];

//now setting a value to one of the array elements...
void SetElement(int element, int value)
{
var1[element]=value;
}

//now to display an array element..
void GetElement(int element)
{
cout<<"Var1["<<element<<"] contains the value "<<var1[element];
//i think this is right might be ...<<var1[element].ToString

//OR do you mean you want to display 'properties' or ..members
//like a class would? eg...var1.

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #3
Hi DAMAR,

This statement should do what you want:

private int[] var1;

public int[] Var1
{
get{
int[] tempVar1=new int[var1.Length];
Array.Copy(var1, tempVar1, var1.Length);
return tempVar1;
}
set{
var1=new int[value.Length];
Array.Copy(value, var1, value.Length);
}
}

HTH
Marcin
Nov 16 '05 #4
Thanx

"Marcin Grzębski" wrote:
Hi DAMAR,

This statement should do what you want:

private int[] var1;

public int[] Var1
{
get{
int[] tempVar1=new int[var1.Length];
Array.Copy(var1, tempVar1, var1.Length);
return tempVar1;
}
set{
var1=new int[value.Length];
Array.Copy(value, var1, value.Length);
}
}

HTH
Marcin

Nov 16 '05 #5

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

Similar topics

4
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
7
by: Anderskj | last post by:
Hi! I am developing a c# application. I have a interface (which can change therefore my problem) If i do like this: List<PropertyInfoproperties = new List<PropertyInfo>();...
0
by: =?Utf-8?B?UmljayBHbG9z?= | last post by:
For some unknown reason (user error?), I cannot get a NameValueCollection to persist in the app.config file. Unlike other settings, I cannot get the String Collection Editor GUI to allow my to...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.