473,836 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass arguments to a property in C#?

Hi,

In vb.Net one can pass arguments to properties. How does one achieve it in c#? Given below is the vb.net code for passing arguments to property getters and setters..

Thanks,
Prachi

Public Property Field(ByVal strFieldName As String, Optional ByVal tableName As String = "", Optional ByVal rowNum As Integer = 0)
Get
If tableName <> "" Then Return objDataSet.Tabl es(tableName).R ows(rowNum)(str FieldName)
Return objDataSet.Tabl es(objDataSet.T ables.Count - 1).Rows(rowNum) (strFieldName)
End Get

Set(ByVal Value)
If tableName <> "" Then
objDataSet.Tabl es(tableName).R ows(rowNum)(str FieldName) = Value
Else
objDataSet.Tabl es(objDataSet.T ables.Count - 1).Rows(rowNum) (strFieldName) = Value
End If
End Set
End Property

Nov 17 '05 #1
15 8417
Prachi Dimble <pr****@eximiuu s.com> wrote:
In vb.Net one can pass arguments to properties. How does one achieve
it in c#? Given below is the vb.net code for passing arguments to
property getters and setters..


In C#, you can only pass parameters to special properties called
indexers. You'll need to make your property an indexer for your class.

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

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Prachi Dimble <pr****@eximiuu s.com> wrote:
In vb.Net one can pass arguments to properties. How does one achieve
it in c#? Given below is the vb.net code for passing arguments to
property getters and setters..


In C#, you can only pass parameters to special properties called
indexers. You'll need to make your property an indexer for your class.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


I think C# is quite cumbersome with this indexer-thingy. I wonder why
Hejlsberg et al decided do go for such complexity, when Delphi sported
parameterized properties in just the way VB.NET does stuff. They shoulod
have known better....

- Michael S
Nov 17 '05 #3
"Michael S" <a@b.c> a écrit dans le message de news:
ua************* @TK2MSFTNGP12.p hx.gbl...
I think C# is quite cumbersome with this indexer-thingy. I wonder why
Hejlsberg et al decided do go for such complexity, when Delphi sported
parameterized properties in just the way VB.NET does stuff. They shoulod
have known better....


Which is why Delphi for .NET as provided (along with C#) by Delphi 2005 is
such a good idea. All the heritage of Delphi in the best OO framework .NET.

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #4
okay!

Thanks,
Prachi

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Prachi Dimble <pr****@eximiuu s.com> wrote:
In vb.Net one can pass arguments to properties. How does one achieve
it in c#? Given below is the vb.net code for passing arguments to
property getters and setters..


In C#, you can only pass parameters to special properties called
indexers. You'll need to make your property an indexer for your class.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5
"Prachi Dimble" <pr****@eximiuu s.com> schrieb im Newsbeitrag
news:eX******** ******@TK2MSFTN GP10.phx.gbl...
Hi,
In vb.Net one can pass arguments to properties. How does one achieve it in
c#? Given below is the vb.net code >for passing arguments to property
getters and setters..
Thanks,
Prachi
Public Property Field(ByVal strFieldName As String, Optional ByVal
tableName As String = "", Optional ByVal >rowNum As Integer = 0)
Get
If tableName <> "" Then Return
objDataSet.Tabl es(tableName).R ows(rowNum)(str FieldName)
Return objDataSet.Tabl es(objDataSet.T ables.Count -
1).Rows(rowNum) (strFieldName)
End Get
Set(ByVal Value)
If tableName <> "" Then
objDataSet.Tabl es(tableName).R ows(rowNum)(str FieldName) = Value
Else
objDataSet.Tabl es(objDataSet.T ables.Count -
1).Rows(rowNum) (strFieldName) = Value
End If
End Set
End Property


Hi Parichi,

to call parameterized properties from VB.NET in C# you have to call the
accessormethods :
field = VBObject.get_Fi eld(...);
VBObject.setFie ld(......,field );
Nov 17 '05 #6
I think it's a simplicity

obj.Field( "string1", "string2", 3)

Is that a method or a property being called?

In C# you know it;s a method. What about with the code provided by the OP ?

IMO if you need to pass parameters you better go with a method.


Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
I think C# is quite cumbersome with this indexer-thingy. I wonder why
Hejlsberg et al decided do go for such complexity, when Delphi sported
parameterized properties in just the way VB.NET does stuff. They shoulod
have known better....

- Michael S

Nov 17 '05 #7
we can use [] notation like the indexers currently do.

I think it'd be a nice feature to have. for example, say I'm implementing a
shopping cart that exposes line items, and I want to access it like

orderEntry = myCart.LineItem s[productID];

currently, I'd have to have a property LineItems that exposes the underlying
line item collection with the indexer. and if this line item collection has
methods that mutates the collection that i don't want to expose outside of
the API, I'd have to mark them as internal, or return some kind of readonly
wrapper.

or alternatively, if parameterized properties are supported, I don't have to
expose the internal collection at all. Just make a property of shopping cart
called LineItems that take product ID as a parameter.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
I think it's a simplicity

obj.Field( "string1", "string2", 3)

Is that a method or a property being called?

In C# you know it;s a method. What about with the code provided by the OP ?

IMO if you need to pass parameters you better go with a method.


Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
I think C# is quite cumbersome with this indexer-thingy. I wonder why
Hejlsberg et al decided do go for such complexity, when Delphi sported
parameterized properties in just the way VB.NET does stuff. They shoulod
have known better....

- Michael S


Nov 17 '05 #8
Indeed.

And C# indexer approach is just a limitation that demands a workaround to
achieve what VB/Delphi sport with grace. But I am curious why Hejlsberg et
al decided to take this approach. For me it makes no sense.

- Michael S

"Daniel Jin" <Da*******@disc ussions.microso ft.com> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
we can use [] notation like the indexers currently do.

I think it'd be a nice feature to have. for example, say I'm implementing
a
shopping cart that exposes line items, and I want to access it like

orderEntry = myCart.LineItem s[productID];

currently, I'd have to have a property LineItems that exposes the
underlying
line item collection with the indexer. and if this line item collection
has
methods that mutates the collection that i don't want to expose outside of
the API, I'd have to mark them as internal, or return some kind of
readonly
wrapper.

or alternatively, if parameterized properties are supported, I don't have
to
expose the internal collection at all. Just make a property of shopping
cart
called LineItems that take product ID as a parameter.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
I think it's a simplicity

obj.Field( "string1", "string2", 3)

Is that a method or a property being called?

In C# you know it;s a method. What about with the code provided by the OP
?

IMO if you need to pass parameters you better go with a method.


Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
> I think C# is quite cumbersome with this indexer-thingy. I wonder why
> Hejlsberg et al decided do go for such complexity, when Delphi sported
> parameterized properties in just the way VB.NET does stuff. They
> shoulod
> have known better....
>
> - Michael S
>
>


Nov 17 '05 #9
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:u3******** ******@TK2MSFTN GP15.phx.gbl...
obj.Field( "string1", "string2", 3)

Is that a method or a property being called?

In C# you know it;s a method. What about with the code provided by the OP

?

Well, since nothing is assigned to it, nor assigned from it, it would
have to be a method in any language, right? ;-)

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 17 '05 #10

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

Similar topics

2
6629
by: Mark | last post by:
Hi - I have a dynamically created table, which has a number of forms - each named consecutively as 'adduserX' where X is a number generated from ASP. Within each form, I need to have a button which will call JavaScript, but pass the name of the form the button is in, as well as a select list name. <input name="check" type="button" onclick="mt_showHilite(this.newname)" value="submit">
41
8347
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by reference?? Thanks, BB
5
11079
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer) modHandler.rptOpen (Me.Report.Name), (Me.Tag) End Sub
7
3903
by: TJ | last post by:
In C# how do you achieve pass-by-reference property declarations in the Type Library? I am writing a COM Class Library that must mimick an existing library for which the only information is the TypeLib. I'm using Visual Studio .NET 2003. The original library provides simple authentication services, from Access and MS-SQL OLEDB providers. The enhancement I'm creating provides support for ODBC and will be a drop-in replacement.
41
2607
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum += arguments;
9
16850
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script type='text/javascript'> function myFunc(lev) { // if (lev) return myFunc(lev-1); var aStack=; nextFunc = arguments.callee;
36
2741
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called on it's own. However when I call the child object I get an error " has no properties (in firefox)." I simple test:
4
9127
by: kinaxx | last post by:
Hello, now I'm learning progamming language in university. but i have some question. in textbook. says there are four passing Mechanism 1) pass by value (inother words : call by value) 2) pass by reference (inother words: call by reference) 3) pass by value-result <- i have question this subject . 4) pass by name
3
2348
by: Davy | last post by:
Hi all, Sometimes I need to pass same parameter in recursive function. From my point of view, the style is redundant, and I don't what to use some global style like self.A, self.B, Is there any other choice? For example, def func(self, x, y, A, B, C): #x, y change in recursive call
0
9810
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...
1
10570
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
9355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7772
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...
0
6972
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5641
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5811
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4438
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
2
4000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.