472,331 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

Is there "Default Peremeter" in C#?

It seems that when I define a fuction,I can set a default value to some of
the peremeters.When I call the fuction without some of them,the fuction will
use the default value automaticlly then continue to work.But I'v fogot how
to use,even I'v fogot whether I can use it in C# or not.
Help me.
Nov 15 '05 #1
18 2130
C# has no default parameters, it uses overloading isntead.
"Clark Nu" <cl*****@hit.edu.cn> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
It seems that when I define a fuction,I can set a default value to some of
the peremeters.When I call the fuction without some of them,the fuction will use the default value automaticlly then continue to work.But I'v fogot how to use,even I'v fogot whether I can use it in C# or not.
Help me.

Nov 15 '05 #2
Could you upate your clock?

José
"Clark Nu" <cl*****@hit.edu.cn> a écrit dans le message de
news:O7**************@TK2MSFTNGP10.phx.gbl...
It seems that when I define a fuction,I can set a default value to some of
the peremeters.When I call the fuction without some of them,the fuction will use the default value automaticlly then continue to work.But I'v fogot how to use,even I'v fogot whether I can use it in C# or not.
Help me.

Nov 15 '05 #3
"news.microsoft.com" <an********@discussions.microsoft.com> schrieb im
Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
C# has no default parameters, it uses overloading isntead.


You name isn't really news.microsoft.com, is it?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #4
OMG REALLY!

"codymanix" <do*********************@gmx.de> wrote in message
news:Ok*************@TK2MSFTNGP11.phx.gbl...
"news.microsoft.com" <an********@discussions.microsoft.com> schrieb im
Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
C# has no default parameters, it uses overloading isntead.


You name isn't really news.microsoft.com, is it?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #5
> "news.microsoft.com" <an********@discussions.microsoft.com> schrieb im
Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
C# has no default parameters, it uses overloading isntead.


You name isn't really news.microsoft.com, is it?


Yeah, I've noticed that guy too. My suspicion is that
"news.microsoft.com" is an Agent. Everyone who has tried to fight this agent
has died. Be extremely careful. Default Params are useful, but they aren't
worth dieing for....
Nov 15 '05 #6
How useful compared to an overloaded method, cand you split out the common
code and just use overloads, overloading is more natural to me. I want to
..Delete() does em all or .Delete(int) does a specific one.

I find coding solutions like that more natural.

"David Sworder" <ds******@cts.com> wrote in message
news:#L*************@TK2MSFTNGP09.phx.gbl...
"news.microsoft.com" <an********@discussions.microsoft.com> schrieb im
Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
C# has no default parameters, it uses overloading isntead.
You name isn't really news.microsoft.com, is it?


Yeah, I've noticed that guy too. My suspicion is that
"news.microsoft.com" is an Agent. Everyone who has tried to fight this

agent has died. Be extremely careful. Default Params are useful, but they aren't
worth dieing for....

Nov 15 '05 #7
actually news.microsoft.com is the default user for posts via
msdn.microsoft.com web site.

"news.microsoft.com" <an********@discussions.microsoft.com> wrote in message
news:#l*************@tk2msftngp13.phx.gbl...
How useful compared to an overloaded method, cand you split out the common
code and just use overloads, overloading is more natural to me. I want to
.Delete() does em all or .Delete(int) does a specific one.

I find coding solutions like that more natural.

"David Sworder" <ds******@cts.com> wrote in message
news:#L*************@TK2MSFTNGP09.phx.gbl...
"news.microsoft.com" <an********@discussions.microsoft.com> schrieb im
Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
> C# has no default parameters, it uses overloading isntead.

You name isn't really news.microsoft.com, is it?


Yeah, I've noticed that guy too. My suspicion is that
"news.microsoft.com" is an Agent. Everyone who has tried to fight this

agent
has died. Be extremely careful. Default Params are useful, but they aren't worth dieing for....


Nov 15 '05 #8
According to C# Pro magazine, all the underlying code in VB.NET does when
you use Optional Params is write the overload for you.... I've looked at
the IL and couldn't verify it, but I'm far from an expert in IL.

I agree too, optionals are eveil.
"David Sworder" <ds******@cts.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
"news.microsoft.com" <an********@discussions.microsoft.com> schrieb im
Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
C# has no default parameters, it uses overloading isntead.
You name isn't really news.microsoft.com, is it?


Yeah, I've noticed that guy too. My suspicion is that
"news.microsoft.com" is an Agent. Everyone who has tried to fight this

agent has died. Be extremely careful. Default Params are useful, but they aren't
worth dieing for....

Nov 15 '05 #9
Oh, he did. To get him to the top of the list no doubt.
Nov 15 '05 #10
Does anyone know why news server take the poster's date? Servers reject messages that are posted in the past, but it seems possible
to post years into the future.

--
Michael Culley
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:u5**************@TK2MSFTNGP10.phx.gbl...
Oh, he did. To get him to the top of the list no doubt.

Nov 15 '05 #11
Oh i could have fun with that :D

*g*
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
Does anyone know why news server take the poster's date? Servers reject messages that are posted in the past, but it seems possible to post years into the future.

--
Michael Culley
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message

news:u5**************@TK2MSFTNGP10.phx.gbl...
Oh, he did. To get him to the top of the list no doubt.


Nov 15 '05 #12

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:uF**************@TK2MSFTNGP11.phx.gbl...
According to C# Pro magazine, all the underlying code in VB.NET does when
you use Optional Params is write the overload for you.... I've looked at
the IL and couldn't verify it, but I'm far from an expert in IL.
Thats not true in any manner I've ever seen. I suspect that article was
incorrect, ;). IL provides full support for declaring optional arguments,
with the OptionalAttribute attribute and the .param attribute in IL, however
it is just information, the language compiler is required to handle using
that information to use optional attributes.
I agree too, optionals are eveil.
"David Sworder" <ds******@cts.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
"news.microsoft.com" <an********@discussions.microsoft.com> schrieb im
Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
> C# has no default parameters, it uses overloading isntead.

You name isn't really news.microsoft.com, is it?


Yeah, I've noticed that guy too. My suspicion is that
"news.microsoft.com" is an Agent. Everyone who has tried to fight this

agent
has died. Be extremely careful. Default Params are useful, but they aren't worth dieing for....


Nov 15 '05 #13
On Sun, 26 Oct 2003 22:53:12 +0100, "news.microsoft.com"
<an********@discussions.microsoft.com> wrote:
actually news.microsoft.com is the default user for posts via
msdn.microsoft.com web site.

That's great, only you aren't using the CDO interface.

Nov 15 '05 #14
On Mon, 27 Oct 2003 00:07:39 GMT, "|{evin" <Yo*@dont.need> wrote:
On Sun, 26 Oct 2003 22:53:12 +0100, "news.microsoft.com"
<an********@discussions.microsoft.com> wrote:
actually news.microsoft.com is the default user for posts via
msdn.microsoft.com web site.

That's great, only you aren't using the CDO interface.


Might I also add that the default user is
"an*******@discussions.microsoft.com" and not "anonymouse" as you
appear to have typo'd.

Nov 15 '05 #15
"news.microsoft.com" <an********@discussions.microsoft.com> wrote in
news:O6**************@TK2MSFTNGP12.phx.gbl:
actually news.microsoft.com is the default user for posts via
msdn.microsoft.com web site.


And why do you have an Outlook Express Posting Header and a typo in
anonymous(e)???

From: "news.microsoft.com" <an********@discussions.microsoft.com>
Subject: Re: Is there "Default Peremeter" in C#?
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: h89n2fls31o1102.telia.com 217.210.97.89

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #16
When I looked at the IL, I did see the option param so I wasn't sure what he
means by "Under the hood" but the inference I got was that ultimately,
that's what's happening (an Option compiles down to an overload). I reread
the article..
http://www.c-sharppro.com/features/2...200310jh_f.asp
(It's the last tip)

Here's the two parts that he mentions:

<<Method overloading lets you create multiple interface signatures for the
same method. This feature is not unique to C#. VB .NET also supports it, for
example, by letting you overload class constructors. VB .NET also uses
method overloading under the hood whenever you use the Optional keyword in a
method signature. I'll illustrate with an example. The VB .NET function
InitSqlCommand initializes and returns an ADO.NET SqlCommand object. The
function accepts an OLE DB connection string and optionally accepts a
command timeout value, which defaults to 180 seconds:>>
And :

<<The key issue here is that C# doesn't support the kinds of shortcuts VB
..NET developers are used to. The benefit of the extra work is you get a
better understanding of what the compiler is really doing. How many VB .NET
developers realize the Optional keyword is a shortcut for method
overloading? In C# you need to know!>>

"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:dJYmb.37490$Tr4.73156@attbi_s03...

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:uF**************@TK2MSFTNGP11.phx.gbl...
According to C# Pro magazine, all the underlying code in VB.NET does when
you use Optional Params is write the overload for you.... I've looked at the IL and couldn't verify it, but I'm far from an expert in IL.
Thats not true in any manner I've ever seen. I suspect that article was
incorrect, ;). IL provides full support for declaring optional arguments,
with the OptionalAttribute attribute and the .param attribute in IL,

however it is just information, the language compiler is required to handle using
that information to use optional attributes.
I agree too, optionals are eveil.
"David Sworder" <ds******@cts.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
> "news.microsoft.com" <an********@discussions.microsoft.com> schrieb im > Newsbeitrag news:#S**************@TK2MSFTNGP11.phx.gbl...
> > C# has no default parameters, it uses overloading isntead.
>
> You name isn't really news.microsoft.com, is it?
>

Yeah, I've noticed that guy too. My suspicion is that
"news.microsoft.com" is an Agent. Everyone who has tried to fight this

agent
has died. Be extremely careful. Default Params are useful, but they

aren't worth dieing for....



Nov 15 '05 #17
And i care?

"|{evin" <Yo*@dont.need> wrote in message
news:ks********************************@4ax.com...
On Sun, 26 Oct 2003 22:53:12 +0100, "news.microsoft.com"
<an********@discussions.microsoft.com> wrote:
actually news.microsoft.com is the default user for posts via
msdn.microsoft.com web site.

That's great, only you aren't using the CDO interface.

Nov 15 '05 #18

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
When I looked at the IL, I did see the option param so I wasn't sure what he means by "Under the hood" but the inference I got was that ultimately,
that's what's happening (an Option compiles down to an overload). I reread the article..
http://www.c-sharppro.com/features/2...200310jh_f.asp
(It's the last tip)

Here's the two parts that he mentions:

<<Method overloading lets you create multiple interface signatures for the
same method. This feature is not unique to C#. VB .NET also supports it, for example, by letting you overload class constructors. VB .NET also uses
method overloading under the hood whenever you use the Optional keyword in a method signature. I'll illustrate with an example. The VB .NET function
InitSqlCommand initializes and returns an ADO.NET SqlCommand object. The
function accepts an OLE DB connection string and optionally accepts a
command timeout value, which defaults to 180 seconds:>>
And :

<<The key issue here is that C# doesn't support the kinds of shortcuts VB
.NET developers are used to. The benefit of the extra work is you get a
better understanding of what the compiler is really doing. How many VB ..NET developers realize the Optional keyword is a shortcut for method
overloading? In C# you need to know!>>

I wonder where that came from, I don't think its accurate...There are
substantial differences between the different methods. Maybe I should write
the author and ask for clarification.
Anyway, I think we've been over this before(maybe over teh same article?) bu
heres a rundown for anyone who is interested:

Method Overloading:
Multiple methods with different parameter sets.
If used to provide default parameters, parameters are loaded in the method.
Client code does not need to recompile to effect a change in behaviour

Optional Parameters:
Single method with a single parameter set.
Can be overloaded as long as the methods differ by more than optional
parameters(in VB.NET atleast)
Default parameters are loaded by the caller. Breaks versioning in some cases
because client code must be recompiled for values to change.
here is some sample IL that shows a method with optional parameters and an
overload of that method.

optional parameters:
..method public instance void Cat([opt] string S,
[opt] string sound) cil managed
{
.param [1] = "neko"
.param [2] = "Nyao"
// Code size 16 (0x10)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: call string [mscorlib]System.String::Concat(string,
string)
IL_0008: call void [mscorlib]System.Console::WriteLine(string)
IL_000d: nop
IL_000e: nop
IL_000f: ret
} // end of method Class1::Cat

and an overload:
..method public instance void Cat(string S,
bool B) cil managed
{
// Code size 22 (0x16)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarga.s B
IL_0004: call instance string [mscorlib]System.Boolean::ToString()
IL_0009: call string [mscorlib]System.String::Concat(string,
string)
IL_000e: call void [mscorlib]System.Console::WriteLine(string)
IL_0013: nop
IL_0014: nop
IL_0015: ret
} // end of method Class1::Cat

which is the IL for the following two subs:
Public Sub Cat(Optional ByVal S As String = "neko", Optional ByVal sound
As String = "Nyao")
Console.WriteLine(S + sound)
End Sub

Public Sub Cat(ByVal S As String, ByVal B As Boolean)
Console.WriteLine(S + B.ToString())

End Sub

Optional parameters do not use overloading, they just expose a similar
interface at the programming level, atleast in all cases I can find.

"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:dJYmb.37490$Tr4.73156@attbi_s03...

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:uF**************@TK2MSFTNGP11.phx.gbl...
According to C# Pro magazine, all the underlying code in VB.NET does when you use Optional Params is write the overload for you.... I've looked at the IL and couldn't verify it, but I'm far from an expert in IL.

Thats not true in any manner I've ever seen. I suspect that article was
incorrect, ;). IL provides full support for declaring optional arguments, with the OptionalAttribute attribute and the .param attribute in IL,

however
it is just information, the language compiler is required to handle using that information to use optional attributes.
I agree too, optionals are eveil.

Nov 15 '05 #19

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

Similar topics

8
by: whtevr | last post by:
Consider this HTML on an ASP page called default.asp in a virtual directory: <FORM name="Flogin" id="Flogin" action="" method=post> </FORM> ...
13
by: DaKoadMunky | last post by:
I recently came across some code in a template that default constructed an object of type T to pass to another function... SomeFunction(T()); ...
9
by: Pierre Senellart | last post by:
The C++ standard states (26.3.2.1), about std::valarray constructors: > explicit valarray(size_t); > > The array created by this constructor has...
12
by: Stefano | last post by:
Hi all, what is the correct use of the "default" attribute in XML Schema? For example: <xs:element name="myProperty" type="xs:string"...
5
by: Hendrik Schober | last post by:
Hi, we just run into the problem, that "default" alignment in the project properies dialog seem to be different. We have a project that's a DLL,...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this?...
15
by: simonoficina | last post by:
Hello all! I am a vb.net beginner in Spain. When I use VB6 ,the button object has a property called "default" that can set this button like press...
3
by: kjworm | last post by:
Greetings, I have a report displayed on a screen that anyone in the office can look at. The data on this report will change from time to time. ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.