473,978 Members | 27,212 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
15 8432

"James Curran" <ja*********@mv ps.org> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl...
"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)

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


Not really.

In Delphi it is pretty straight forward as there are language constructs
that shows that a property is mapped to a field.

fCount: Integer;
property Count: integer read fCount;

Hence the compiler simply map the property Count to the virtual address of
fCount.

In managed langauges, as Java and CIL; there is no such thing as a property.
C# have properties as syntactic sugar for getters and setters, but as you
said; CIL only sports methods.

But the Just In Time Compiler (JIT) will optimize and scan all get and set
methods. If the methods is just read and assignment to fields it will be
inlined.

Hence..

private int count;
public int Count
{
get
{
return count;
}
}

.... would never yield a method call to get_Count, but map straight to the
virtual address of count.

This is true for both Java and CIL.

JITters are quite smart. Just look how they manages strings:

int digit = 2;
string strsimple = "1" + digit.ToString( ) + "3";

C# implies that two calls are made to an overridden + operator method on the
class System.String in conjunction with the ToString() method. Luckely for
us, and our users, this is not what we get, as it would give us the
performance of a snail =)

The JITter could care no less about language constructs in C# and CIL, and
simply calculate the size of the strings and allocate a a new string and
then copy the buffers. No methods called whatsoever. Really!

But what about this?

string str = "Hello, " + name + "!" + " It is " + day + " and the weather is
" + weather + ". Have a nice day!";

In this case, the JITter would actually create a StringBuilder (StringBuffer
in Java).
And you might think it would use be something like
tempstr.Append( ...).Append(..) .Append(...).To String();

But No! There is no such thing as an Append method on a StringBuilder when
it comes actual runtime. That method will be replaced by the JITter with
proper cpu-instructions for moving unicode, depending on what cpu you got.
And future computers will have a unicode-chip that does encodings in
hardware. Strings will be faster...

This is what we love about Managed Code. We get all the sugar from C#
syntax, and the JITter can become smarter and smarter, move to better and
better computers, without breaking any code.

What you write in C# is not WYSIWYG but WYSGDSTYT

WYSIWYG - What You See Is What You Get
WYSGDSTYT- What You See Gets Done Smarter Than You Think

Regards
- Michael S
Nov 17 '05 #11
Michael S <a@b.c> wrote:
But what about this?

string str = "Hello, " + name + "!" + " It is " + day + " and the weather is
" + weather + ". Have a nice day!";

In this case, the JITter would actually create a StringBuilder (StringBuffer
in Java).
In Java this is accurate, although the calls are created by the Java
compiler, not the JIT compiler. (Hopefully in Java 1.5 it uses the new
Java StringBuilder instead, which doesn't synchronize - I haven't
checked though.)

In C#, String.Concat is used instead of a StringBuilder.
But No! There is no such thing as an Append method on a StringBuilder when
it comes actual runtime.
Um, I rather think there is.
That method will be replaced by the JITter with
proper cpu-instructions for moving unicode, depending on what cpu you got.


Certainly within the method there will be CPU instructions, obviously,
and the method *may* be inlined by the JIT, but it won't always be.
(Consider a reflection call.)

--
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 #12
Michael S <a@b.c> wrote:
But what about this?

string str = "Hello, " + name + "!" + " It is " + day + " and the weather is
" + weather + ". Have a nice day!";

In this case, the JITter would actually create a StringBuilder (StringBuffer
in Java).
In Java this is accurate, although the calls are created by the Java
compiler, not the JIT compiler. (Hopefully in Java 1.5 it uses the new
Java StringBuilder instead, which doesn't synchronize - I haven't
checked though.)

In C#, String.Concat is used instead of a StringBuilder.
But No! There is no such thing as an Append method on a StringBuilder when
it comes actual runtime.
Um, I rather think there is.
That method will be replaced by the JITter with
proper cpu-instructions for moving unicode, depending on what cpu you got.


Certainly within the method there will be CPU instructions, obviously,
and the method *may* be inlined by the JIT, but it won't always be.
(Consider a reflection call.)

--
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 #13
Hello,

You can check out www.eassignment.net for help with your assignments.
They are really helpful.

Simon Tanner

Nov 17 '05 #14
"Michael S" <a@b.c> wrote in message
news:el******** *****@TK2MSFTNG P12.phx.gbl...
"James Curran" <ja*********@mv ps.org> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl...
obj.Field( "string1", "string2", 3) Well, since nothing is assigned to it, nor assigned from it, it would
have to be a method in any language, right? ;-)


Not really.

In Delphi it is pretty straight forward as there are language constructs
that shows that a property is mapped to a field.
[snip]


You seemed to have competely missed my point.

The original statement was :

obj.Field( "string1", "string2", 3)
Is that a method or a property being called?

I was trying to point out, that had it been written as:
int x = obj.Field( "string1", "string2", 3)
then we truly couldn't tell if it were a method or a property. But, as it
was written as
obj.Field( "string1", "string2", 3)
it would have to be either:
a) a method, called for it's side effects.
b) a property, with side-effects (ie, a method pretending to be a
property), or
c) a property without side-effect (ie, in this case, a NOP)

Hence, we can safely conclude, if it's not an error, it's a method.

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

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

fCount: Integer;
property Count: integer read fCount;

Hence the compiler simply map the property Count to the virtual address of
fCount.

In managed langauges, as Java and CIL; there is no such thing as a property. C# have properties as syntactic sugar for getters and setters, but as you
said; CIL only sports methods.

But the Just In Time Compiler (JIT) will optimize and scan all get and set
methods. If the methods is just read and assignment to fields it will be
inlined.

Hence..

private int count;
public int Count
{
get
{
return count;
}
}

... would never yield a method call to get_Count, but map straight to the
virtual address of count.

This is true for both Java and CIL.

JITters are quite smart. Just look how they manages strings:

int digit = 2;
string strsimple = "1" + digit.ToString( ) + "3";

C# implies that two calls are made to an overridden + operator method on the class System.String in conjunction with the ToString() method. Luckely for
us, and our users, this is not what we get, as it would give us the
performance of a snail =)

The JITter could care no less about language constructs in C# and CIL, and
simply calculate the size of the strings and allocate a a new string and
then copy the buffers. No methods called whatsoever. Really!

But what about this?

string str = "Hello, " + name + "!" + " It is " + day + " and the weather is " + weather + ". Have a nice day!";

In this case, the JITter would actually create a StringBuilder (StringBuffer in Java).
And you might think it would use be something like
tempstr.Append( ...).Append(..) .Append(...).To String();

But No! There is no such thing as an Append method on a StringBuilder when
it comes actual runtime. That method will be replaced by the JITter with
proper cpu-instructions for moving unicode, depending on what cpu you got.
And future computers will have a unicode-chip that does encodings in
hardware. Strings will be faster...

This is what we love about Managed Code. We get all the sugar from C#
syntax, and the JITter can become smarter and smarter, move to better and
better computers, without breaking any code.

What you write in C# is not WYSIWYG but WYSGDSTYT

WYSIWYG - What You See Is What You Get
WYSGDSTYT- What You See Gets Done Smarter Than You Think

Regards
- Michael S

Nov 17 '05 #15

"James Curran" <ja*********@mv ps.org> wrote in message
news:eb******** ******@TK2MSFTN GP15.phx.gbl...
"Michael S" <a@b.c> wrote in message
news:el******** *****@TK2MSFTNG P12.phx.gbl...
"James Curran" <ja*********@mv ps.org> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl...
>> obj.Field( "string1", "string2", 3)
> Well, since nothing is assigned to it, nor assigned from it, it
> would
> have to be a method in any language, right? ;-)


Not really.

In Delphi it is pretty straight forward as there are language constructs
that shows that a property is mapped to a field.
[snip]


You seemed to have competely missed my point.


Not really.

The original obj.Field( "string1", "string2", 3) is actual a property taking
arguments.
However, the terrible VB syntax makes it look like a method.

Hence, You miss-read the OP and I miss-read you.. What a mess. =)

- Michael S
Nov 17 '05 #16

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

Similar topics

2
6638
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
8411
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
11090
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
3913
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
2647
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
16875
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
2760
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
9139
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
2353
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
10358
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
10175
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
11833
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...
1
11593
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
7620
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
6424
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
6562
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5162
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
4742
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.