473,327 Members | 1,952 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,327 software developers and data experts.

optional keyword in c#

how to define the optional parameters for a method or
function in c# ?

I am trying to convert an application from VB.NET to c#,
and don't know how to do the above without overloading.

Thanks,

Tapasvi

Nov 15 '05 #1
6 5522
Tapasvi Mehta wrote:
how to define the optional parameters for a method or
function in c# ?


You can't. The closest you can get is a params which allows for an
arbitrary number of parameters.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2

"Tapasvi Mehta" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl...
how to define the optional parameters for a method or
function in c# ?

I am trying to convert an application from VB.NET to c#,
and don't know how to do the above without overloading.

You can't, you have to use overloading.
Thanks,

Tapasvi

Nov 15 '05 #3
Is it possible to default to a value for a parameter ?
-----Original Message-----

"Tapasvi Mehta" <an*******@discussions.microsoft.com> wrote in messagenews:0c****************************@phx.gbl...
how to define the optional parameters for a method or
function in c# ?

I am trying to convert an application from VB.NET to c#,
and don't know how to do the above without overloading.


You can't, you have to use overloading.
Thanks,

Tapasvi

.

Nov 15 '05 #4
Tapasvi,

No, it is not. Basically, say you have a method like this:

public void DoSomething(int myParam)

If you want to have a default value, you would create an overload that
does this:

public void DoSomething()
{
// Call the overload, passing a default value of one.
DoSomething(1);
}

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

"Tapasvi Mehta" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl...
Is it possible to default to a value for a parameter ?
-----Original Message-----

"Tapasvi Mehta" <an*******@discussions.microsoft.com>

wrote in message
news:0c****************************@phx.gbl...
how to define the optional parameters for a method or
function in c# ?

I am trying to convert an application from VB.NET to c#,
and don't know how to do the above without overloading.


You can't, you have to use overloading.
Thanks,

Tapasvi

.

Nov 15 '05 #5
Tapasvi Mehta <an*******@discussions.microsoft.com> wrote:
Is it possible to default to a value for a parameter ?


No. What would be the point, if you then couldn't also make it
optional?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Thanks to all for helping out.
-----Original Message-----
Tapasvi,

No, it is not. Basically, say you have a method like this:
public void DoSomething(int myParam)

If you want to have a default value, you would create an overload thatdoes this:

public void DoSomething()
{
// Call the overload, passing a default value of one.
DoSomething(1);
}

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

"Tapasvi Mehta" <an*******@discussions.microsoft.com> wrote in messagenews:0c****************************@phx.gbl...
Is it possible to default to a value for a parameter ?
>-----Original Message-----
>
>"Tapasvi Mehta" <an*******@discussions.microsoft.com>

wrote in message
>news:0c****************************@phx.gbl...
>> how to define the optional parameters for a method or
>> function in c# ?
>>
>> I am trying to convert an application from VB.NET to c#, >> and don't know how to do the above without overloading. >>
>
>You can't, you have to use overloading.
>
>> Thanks,
>>
>> Tapasvi
>>
>
>
>.
>

.

Nov 15 '05 #7

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

Similar topics

49
by: bearophileHUGS | last post by:
Adding Optional Static Typing to Python looks like a quite complex thing, but useful too: http://www.artima.com/weblogs/viewpost.jsp?thread=85551 I have just a couple of notes: Boo...
5
by: (Pete Cresswell) | last post by:
I've dabbled in "Optional" over the last few days and think I'm coming down against using it. Seems to me like it makes the code harder to read and more complicated. Instead of using Optional,...
13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
1
by: Doug Zody | last post by:
How to make function argument as optional in Vb.Net? I have a function signature as shown below. I am using .Net Framework 1.1. Public Shared Function Foo(ByVal strCustNo As String, ByRef...
34
by: Mike Labosh | last post by:
VS.NET 2003, ASP.NET Project with Option Strict turned ON. (yes, I know this is not the aspnet group. This is a VB syntax thing, not an ASP.NET thing) This actually compiles without the...
12
by: Nick Hounsome | last post by:
Can anyone tell me what the rational is for not supporting optional arguments. It is obviously a trivial thing to implement and, since C++ has them, I would not expect them to be omitted without...
2
by: dhable | last post by:
If I'm building a function to accept optional parameters, do I need to allow for the capture of both the positional arguments as well as the keyword arguments? If it doesn't make sense to allow...
2
by: Nathan Harmston | last post by:
Hi, I know this isnt the pyparsing list, but it doesnt seem like there is one. I m trying to use pyparsing to parse a file however I cant get the Optional keyword to work. My file generally...
1
by: thesti | last post by:
hi, i'm kinda confuse about how the optional keyword relates to a method signature. as a method with optional parameters has multiple method signature in VB.net if i declare the following...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.