Creating a Default function

D

Dmitriy Lapshin [C# / .NET MVP]

Hello Simon,

Not sure what does this keyword mean in VB .NET... If this is an indication
of the default property (the one that can be referenced without specifying
the property name), then you are limited to argument-overloadable indexers
(which work in a very similar way) in C#. Please also note that this is the
only way to have a property with arguments in C#.
 
C

cody

How do I make a function the "default" function? In VB.NET its the keyword
default, is there a C# equivalent?


What to hell is a default function? Please explain.
 
C

cody

In VB .NET you can set a function etc to be the default. This means that
you
don't need to specify the name of function for example:

MyObject.Item(0)

can be replaced with just:

MyObject(0)

This is no default function, it is an indexer.

in C# you declare an indexer like that:

int this(int index)
{
get { return array[index] ; }
set { array[index] =value; }
}
 
R

Rahul Anand

What you are looking for is called Indexer in C#.

An indexer is similar to a property. As with properties,
you use get and set when defining an indexer. Unlike
properties, you are not obtaining a specific data member;
rather, you are obtaining a value from the object itself.

The format for defining an indexer is:

public dataType this[int index]
{
get
{
// Do whatever you want...
return aValue;
}
set
{
// Do whatever you want
// Generally you should set a value within the
class
// based on the index and the value they assign.
}
}


Check the thread "Default Properties" in this group, for
more info.

And the following link may provide more help:
http://www.codeguru.com/Csharp/Csharp/cs_syntax/indexers/ar
ticle.php/c5833/
 
J

Jeffrey Tan[MSFT]

Hi Simon,

I think you have got a lot of useful feedback from the community. Does the
community's reply make sense to you?

Do you still have any concern on this issue? Please feel free to post.
Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top