473,321 Members | 1,669 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,321 software developers and data experts.

Does C# provide array properties (as in Delphi)?

Does C# have the ability to define array properties, as in Delphi? For
example, does the following have an equivalent in C#?

type
TMyGrid = class

{ ...some code... }

property IntegerCells[i, j: Integer]: Integer read GetIntegerCell write
SetIntegerCell;
property StringCells[i, j: Integer]: Integer read GetStringCell write
SetStringCell;

{ ...some code... }

end;
Jul 19 '07 #1
3 1806
No, you can only do this for indexers, but not for properties. This is a
real annoyance in C# (you can do it in VB.NET, so why not in C# is anybody's
guess).

"Debbie Croft" <de**********@nospamforme.comwrote in message
news:13*************@corp.supernews.com...
Does C# have the ability to define array properties, as in Delphi? For
example, does the following have an equivalent in C#?

type
TMyGrid = class

{ ...some code... }

property IntegerCells[i, j: Integer]: Integer read GetIntegerCell write
SetIntegerCell;
property StringCells[i, j: Integer]: Integer read GetStringCell write
SetStringCell;

{ ...some code... }

end;

Jul 19 '07 #2
On Jul 19, 3:48 am, "Clive Dixon" <clived at digita dot comwrote:
No, you can only do this for indexers, but not for properties. This is a
real annoyance in C# (you can do it in VB.NET, so why not in C# is anybody's
guess).

"Debbie Croft" <debbie.cr...@nospamforme.comwrote in message

news:13*************@corp.supernews.com...
Does C# have the ability to define array properties, as in Delphi? For
example, does the following have an equivalent in C#?
type
TMyGrid = class
{ ...some code... }
property IntegerCells[i, j: Integer]: Integer read GetIntegerCell write
SetIntegerCell;
property StringCells[i, j: Integer]: Integer read GetStringCell write
SetStringCell;
{ ...some code... }
end;
Yes, but you can have a property that is a 2 dimensional array:

private int[,] _myArray;
public int[,] MyArray {
get { return _myArray; }
set { _myArray = value; }
}

Then initialize it and use it with this code:

this.MyArray = new int[10,10];
this.MyArray[5,5] = 25;

Chris

Jul 19 '07 #3
"Chris Dunaway" <du******@gmail.comwrote:
Yes, but you can have a property that is a 2 dimensional array:
private int[,] _myArray;
public int[,] MyArray {
get { return _myArray; }
set { _myArray = value; }
}
Not very safe when one caller might completely replace the array that
another one wrote to!

Eq.
Jul 19 '07 #4

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

Similar topics

4
by: exitus | last post by:
Is there a way to dynamically resize an array along with maintaining its contents similar to VB's REDIM PRESERVE statement in C#? My problem is, the user won't be sure how big the string array...
1
by: BuddyWork | last post by:
Hello, Sorry I posted this message in the newsgroup, as I could not find an IIS group. I'm running Windows XP Professional and when I try to display the Properties dialog by pressing right...
11
by: benben | last post by:
Recently I have come across a number of struct's that I think is quite interesting: typedef struct whatever_tag { int member1; char member2; // ... char last_member; // interesting line
7
by: jose.cortijo | last post by:
Hi everybody, I would like to access to one variable by an indirect mode. I would try to explain myself: I have like twelve variables and all of them are global scope. The point is that I...
1
by: Mythran | last post by:
How can I set a DefaultValue for an array property? I don't have a project that uses this anymore, but still am curious. Of all the replies I've posted here, a simple thing like this is my...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4. Is there a shorter way to check if an array has an element besides doing a for loop and iterating through each element? Thanks, - Dave
2
by: Velislav | last post by:
Hi, I've got the following piece of code: string GetPropertyValue(object jobCard, string propertyName, int index) { PropertyInfo property = jobCard.GetType().GetProperty(propertyName); if...
2
by: Rick Giuly | last post by:
Hello All, Case 1 This generates an error, which makes sense because the argument should be a list of numbers: numpy.array(10,10) Case 2 This does not generate an error and the result is an...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.