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

Why no array property in C#.

I have been using Delphi for a few years, now using Delphi8 and VC#. I
just had a preview on VC# 2.0.

I was wondering why there is no array property? While there is in
VB.net, Delphi.net and IL.

For example, in Delphi, I could have

tStringsObject.strings[i];
tStringsObject.values['something'];
tstringsObject.keys[b];

Array property looks like an array, but does not necessarily need data
buffers.

Array property is really handy for writing/wiring components and
wrapping classes and data.

In C#, you could only have indexer which one for one class. Now when I
port some Delphi code or Delphi 8 codes to C#, I have to change the
interfaces to methods.

I had contacted the Microsoft C# team, and they said they had chose
not to support array property long time ago. "We chose simplicity over
flexibility in this case."
I understand that properties and array properties are essentially
member functions of a class. Published properties could appear on the
object inspector for you to define a collection of items of an array
property at design time.

Without array property, I have to then write codes to initialize items
of a collection. This is not good for RAD.

I heard from a 2-day dot Net seminar, Microsoft is not worried about
its dominant position on desktop applications, Microsoft is much
concerned by Linux on the server markets. Dot Net and C# mostly focus
on server, on which RAD development is not as appeal as on desktop.

I think this is one of the key factors why MS C# team did not want to
implement array property.

Best regards

Dingdang
Nov 16 '05 #1
10 7167
Ding Dang wrote:

Array property looks like an array, but does not necessarily need data
buffers. Without array property, I have to then write codes to initialize items
of a collection.


No you don't. Define you property as a instance of an internally
defined class. Define an indexer for that.

// Warning : untested code.
class StringsObject
{
private class SO_string
{
public string this[](int i) { ....}
}

public SO_string strings
{
get { .....}
}
}
--
Truth,
James Curran [MVP]
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)


Nov 16 '05 #2
James Curran wrote:
Ding Dang wrote:
Array property looks like an array, but does not necessarily need data
buffers.


Without array property, I have to then write codes to initialize items
of a collection.

No you don't. Define you property as a instance of an internally
defined class. Define an indexer for that.

// Warning : untested code.
class StringsObject
{
private class SO_string
{
public string this[](int i) { ....}
}

public SO_string strings
{
get { .....}
}
}

Hm. that's interesting! Can you put a working piece of code? I just want to understand how exactly
to use it... I am still kinda newbie ;)
Thank you
Andrey
Nov 16 '05 #3
> Dot Net and C# mostly focus
on server, on which RAD development is not as appeal as on desktop.


Who said that?

--
William Stacey, MVP

Nov 16 '05 #4
Hi,

Take a look at this Indexer tutorial
http://msdn.microsoft.com/library/de...rsTutorial.asp

Regards,
Vikram, S

"Andrey" wrote:
James Curran wrote:
Ding Dang wrote:
Array property looks like an array, but does not necessarily need data
buffers.


Without array property, I have to then write codes to initialize items
of a collection.

No you don't. Define you property as a instance of an internally
defined class. Define an indexer for that.

// Warning : untested code.
class StringsObject
{
private class SO_string
{
public string this[](int i) { ....}
}

public SO_string strings
{
get { .....}
}
}

Hm. that's interesting! Can you put a working piece of code? I just want to understand how exactly
to use it... I am still kinda newbie ;)
Thank you
Andrey

Nov 16 '05 #5
James,

If the class is internally defined then how would a client know anything
about that internally defined type? The fact that it's exposed as a public
property would do you no good if you don't have a type definition to work
from.

What's wrong with:

class SO_string {
public string this[](int i) {...}
}

class StringsObject {
private SO_string so_string = new SO_string();

public SO_string strings {get {this.so_string;}}
}

--Bob

"James Curran" <Ja*********@mvps.org> wrote in message
news:up*************@TK2MSFTNGP11.phx.gbl...
No you don't. Define you property as a instance of an internally
defined class. Define an indexer for that.

// Warning : untested code.
class StringsObject
{
private class SO_string
{
public string this[](int i) { ....}
}

public SO_string strings
{
get { .....}
}
}

Nov 16 '05 #6
Bob Grommes wrote:
If the class is internally defined then how would a client know
anything about that internally defined type? The fact that it's
exposed as a public property would do you no good if you don't have a
type definition to work from.


You're right (There are reasons why I label such things as "untested
code")
--
Truth,
James Curran [MVP]
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)


Nov 16 '05 #7
OK, fully working code:
using System;
namespace PropertyArray
{
class StringsObject
{
public class SO_string
{
public string this[int i]
{
get
{
return i.ToString(); /// put something useful here.
}
}
}
private SO_string my_sos = new SO_string();
public SO_string strings
{
get {return my_sos; }
}
}
//-------------------------------------------------
class Class1
{
[STAThread]
static void Main(string[] args)
{
StringsObject so = new StringsObject();
Console.WriteLine(so.strings[456]);
}
}
}
--
Truth,
James Curran [MVP]
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)
Nov 16 '05 #8
Ding Dang <di******@ihug.com.au> wrote:

<snip>
I heard from a 2-day dot Net seminar, Microsoft is not worried about
its dominant position on desktop applications, Microsoft is much
concerned by Linux on the server markets. Dot Net and C# mostly focus
on server, on which RAD development is not as appeal as on desktop.

I think this is one of the key factors why MS C# team did not want to
implement array property.


I don't think that's really a factor, to be honest. Properties with
parameters are just as useful in non-RAD development. This is one place
where I think Anders got it wrong, unfortunately. :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9
You could overload a class indexer. This way you could have more than
one class indexer in a class.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #10
Ravichandran J.V. <jv************@yahoo.com> wrote:
You could overload a class indexer. This way you could have more than
one class indexer in a class.


Yes, but it doesn't allow you to give them different names and access
them via the names, unfortunately.

For instance, suppose I have a class with some names in. It would be
nice to be able to do:

public class Foo
{
string[] names;

public string Names[int index]
{
get { return names[index]; }
}

// ...
}

rather than either exposing the names array itself (dangerous - you
can't keep it readonly) or creating a different class to expose the
values.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #11

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

Similar topics

8
by: point | last post by:
Hi there.. I have the folowing array => property = hexonet => property = 2003-12-01 18:46:20.0 => property = hexonet => property = 2003-12-02 02:59:15.0 => property = hexonet =>...
5
by: Denis Perelyubskiy | last post by:
Hello, I need to make an array of elements accross forms. My javascript skills, as evident from this question, are rather rudimentary. I tried to make an associative array and index it with...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
7
by: Robert Mark Bram | last post by:
Hi All! How do you get the length of an associative array? var my_cars= new Array() my_cars="Mustang"; my_cars="Station Wagon"; my_cars="SUV"; alert(my_cars.length);
5
by: Jon Maz | last post by:
Hi All, I'm reasonably proficient with C#, and am starting with php5. I was happy to learn of the __get and __set methods, but am encountering a problem using them to set an object property of...
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.