473,379 Members | 1,190 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,379 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 2218
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> Do I HAVE to put the literal "default.asp" into the...
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()); The code that instantiates that template specifies...
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 a length equal to the value of > the argument....
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" default="myDefaultValue"/> What can I do with it? What...
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, which is linked with a couple of LIBs. All are...
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? Mixed-mode is incredibly convenient, but if I...
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 "ENTER" key. But in the VB.net I can't find this...
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. This report has different colors displayed...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...

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.