473,808 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7191
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*********@mv ps.org> wrote in message
news:up******** *****@TK2MSFTNG P11.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.WriteLi ne(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.co m>
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.Ravichandra n
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandra n+J.V.&cob=aspn etpro
- 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.Ravichandr an"
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

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

Similar topics

8
906
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 => property = 2004-12-01 18:46:20.0
5
6540
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 the object references. However, I just realized that indices may only be referenced by strings.
47
5098
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 are not at all. If you are doing *array", then you have to use only integer values for array index, as it was since ALGOL.
22
4656
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 month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and hash is the base for it. I summarized all points in this article:...
35
6683
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
39853
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
5539
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 type "array". Below is a simple example of the problem I'm having with a sample object "Article", which has an array property "authors". As you can see, I can't even use standard php array syntax to set a single author, even though the same...
38
5242
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 let's us do not go into an "each dot over i" clarification discussion now - however you want to call - you call it ;-) array contains records of all files in the current dir. array contains records of all subs in the current dir
21
3229
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 column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a comma delimited list of values var jsData = new Array(); jsData = {lib: "#field...
2
2519
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 the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10631
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.