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

C-Sharp Help on Default Properties..Help

I am using the Windows MCAD/MCSD book on VB.NET/VC.NET to refresh myself on
some C# concepts and I ran into one issue in the properties area I just do
not understand. In VB.NET this is easy to understand, in VC.NET I am lost,
can someone simplify it for me?

Here is some sample code:

public int this[int Index]
{
get
{
return intArray[Index];
}
set
{
intArray[Index] = value;
}
}

What is the dafault property? I cannot tell by reading this sample from the
book.
Nov 15 '05 #1
3 1469
This means, you can access your object just like how you would with an
array.

For example, if your class was named FooClass, you can do something like
this:

FooClass foo = new FooClass();
int i = foo[0];

When you dereference foo with foo[0], you are actually calling the property
you just defined.

-vJ

"CodeToad" <jb******@cox.net> wrote in message
news:ex6Eb.4557$Fg.3892@lakeread01...
I am using the Windows MCAD/MCSD book on VB.NET/VC.NET to refresh myself on some C# concepts and I ran into one issue in the properties area I just do
not understand. In VB.NET this is easy to understand, in VC.NET I am lost, can someone simplify it for me?

Here is some sample code:

public int this[int Index]
{
get
{
return intArray[Index];
}
set
{
intArray[Index] = value;
}
}

What is the dafault property? I cannot tell by reading this sample from the book.

Nov 15 '05 #2

you can define a property just like this:
public int MyProperty
{
get
{
return MyIntValue;
}
set
{
MyReturnValue = value;
}
}
What you see is another thing.
Nov 15 '05 #3
In vb.net, you create a "real" property (for example, an Item property) and
decorate it with the Default keyword, such as:

Default Public Property Item(Index As Integer) ...

You can then invoke this member by using either one of two syntax choices:

x = MyObject.Item(3)
or
x = MyObject(3)

Since Item is the Default property, you don't need to spell it out to invoke
it, and it helps you make properties that behave more or less like indexed
values.

C# doesn't have quite the same flexibility. In C# you can only create ONE
indexed property (and it is automatically named Item by default), though you
can overload it.
C# assumes you will invoke the "indexer" by using

x = MyObject[3];

Pity, because C# has no way to define multiple properties with paramters
(not just the DEFAULT indexer), and the VB.NET syntax is actually closer to
what the compiled IL looks like. To me, C# just made it confusing and
inflexible.

-Rob Teixeira [MVP]

"CodeToad" <jb******@cox.net> wrote in message
news:ex6Eb.4557$Fg.3892@lakeread01...
I am using the Windows MCAD/MCSD book on VB.NET/VC.NET to refresh myself on some C# concepts and I ran into one issue in the properties area I just do
not understand. In VB.NET this is easy to understand, in VC.NET I am lost, can someone simplify it for me?

Here is some sample code:

public int this[int Index]
{
get
{
return intArray[Index];
}
set
{
intArray[Index] = value;
}
}

What is the dafault property? I cannot tell by reading this sample from the book.

Nov 15 '05 #4

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

Similar topics

1
by: Rosenfeld Yonatan | last post by:
hi , i am searching a way to change the summary title , subject or any other properties, and i not founding anything in the File class or the FileInfo class. how can i change this properties. ...
5
by: Chuck Bowling | last post by:
Maybe I'm doing something wrong or just don't understand the concept, but i'm having a problem with default properties. My impression of how a default property should act is this; MyClass c =...
0
by: Chad Myers | last post by:
*** I posted this in the interop newsgroup, but I'm not sure if it'd get answered there. I didn't want to cross post and possible bug everyone, so sorry if I made a faux-paus. *** I'm writing...
3
by: countd4 | last post by:
I have built a working user control. However, to make it work, I always have to set certian properties using the properties sheet for the control when using it on other forms. I want to be able to...
2
by: Michael Rodriguez | last post by:
If I subclass TextBox and add my own new properties, how do I set their default values? I tried assigning them in the default constructor, but they still show as bold in the object inspector and...
4
by: XNoDE | last post by:
Hi all, VS.Net 2002. Is there a way to set default properties for controls in the Toolbox? There a some properties that I implement as standard in my apps and would like to get around...
2
by: mike | last post by:
I have received the following upgrade warning in several apps Couldn't resolve default property of object Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037" ...
3
by: ken | last post by:
Hi, I want to reset the default value of a combo box everytime someone selects something from its list. I have in the after update event combo.defaultvalue = combo.value. Anyhow this works, as...
2
by: gella | last post by:
i would like to change the default color of hyperlink in datagrid. the defult color is blue.Is it possible to change the hyperlink column's default blue color to another color..
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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,...
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
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...
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,...

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.