473,385 Members | 2,004 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,385 software developers and data experts.

C# equivalent for VB Class DEFAULT method

In VB, I could assign a "Default" to a class method. In that way, a
reference to the Class always returns the result of that
method/property (i.e. a reference to a textbox control always returns
the contents of textbox.text).
What is the C# equivalent? Is it the Indexer for that class?

--
John Wood
Nov 16 '05 #1
3 1831
Mortimer,

The indexer is the only thing on a class that can be called by default.
Personally, I think that it is very dangerous to have such a thing (not
indexers, but default properties), because it creates ambiguities in the
code. One of my biggest pet peeves was ADO, when using a recordset, you
could do:

' pobjRs is an ADODB.Recordset
pobjRs("fieldName")

Where the above is shorthand for:

pobjRs.Fields.Item("fieldName").Value

The latter piece of code gives a much better idea of what the intent is,
IMO.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mortimer Schnurd" <fu**********@hotsmail.com> wrote in message
news:dg********************************@4ax.com...
In VB, I could assign a "Default" to a class method. In that way, a
reference to the Class always returns the result of that
method/property (i.e. a reference to a textbox control always returns
the contents of textbox.text).
What is the C# equivalent? Is it the Indexer for that class?

--
John Wood

Nov 16 '05 #2
On Thu, 1 Apr 2004 09:19:00 -0500, in msg
<uC**************@TK2MSFTNGP11.phx.gbl>, "Nicholas Paldino [.NET/C#
MVP]" <mv*@spam.guard.caspershouse.com> wrote:
Mortimer,

The indexer is the only thing on a class that can be called by default.
Personally, I think that it is very dangerous to have such a thing (not
indexers, but default properties), because it creates ambiguities in the
code. One of my biggest pet peeves was ADO, when using a recordset, you
could do:


Thanks Nicholas, that does help. I do agree with your philosophy
regarding defaults and I rarely ever use them in code, However,
assigning a default in a VB class made it very easy for me to identify
content while debugging and "hovering" over an object.

--
Regards,
John Wood

--
John Wood a.k.a Mortimer Schnurd
http://www.loosemarbles.com
Nov 16 '05 #3

"Mortimer Schnurd" <fu**********@hotsmail.com> wrote in message
news:21********************************@4ax.com...
On Thu, 1 Apr 2004 09:19:00 -0500, in msg
<uC**************@TK2MSFTNGP11.phx.gbl>, "Nicholas Paldino [.NET/C#
MVP]" <mv*@spam.guard.caspershouse.com> wrote:
Mortimer,

The indexer is the only thing on a class that can be called by default.Personally, I think that it is very dangerous to have such a thing (not
indexers, but default properties), because it creates ambiguities in the
code. One of my biggest pet peeves was ADO, when using a recordset, you
could do:


Thanks Nicholas, that does help. I do agree with your philosophy
regarding defaults and I rarely ever use them in code, However,
assigning a default in a VB class made it very easy for me to identify
content while debugging and "hovering" over an object.

--
Regards,
John Wood

--
John Wood a.k.a Mortimer Schnurd
http://www.loosemarbles.com

Would an override of the ToString() method help here?

Hans Kesting
Nov 16 '05 #4

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

Similar topics

3
by: Gabriel Cooper | last post by:
What is the python equivalent to java's toString()? When debugging I want to be able to basically be able to do this: print MyObjectInstance or print str(MyObjectInstance) and have it...
16
by: jonathan cano | last post by:
QUESTION: In practice, lines 36 and 37 below are usually equivalent to the default copy constructor (.e.g line 33). My questions are: (a) Does ISO 14882 guarantee that lines 36 and 37 are...
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
4
by: Mullin Yu | last post by:
I want to know what's the equivalent of COM dll at .NET platform? I want to build a .NET component and will be reused by other .NET application. Any links/sample code to teach this? Thanks!
8
by: FDude | last post by:
In otherwords, how do I force a method in my class to call the method implementations in the SAME class and not use any potentially overriden methods in derived classes?
3
by: Mortimer Schnurd | last post by:
In VB, I could assign a "Default" to a class method. In that way, a reference to the Class always returns the result of that method/property (i.e. a reference to a textbox control always returns...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
3
by: chris | last post by:
Hello Group, All I wanna do is to get the contents of a web page and display it in my application. VB 6.0 has the INet control. How do I do it using VB.NET/ Thanks for the help, Chris.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.