Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 981423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:32:26+00:00 2026-05-16T04:32:26+00:00

MSDN’s VS2010 Named and Optional Arguments (C# Programming Guide) tells us about optional parameters

  • 0

MSDN’s VS2010 Named and Optional Arguments (C# Programming Guide) tells us about optional parameters in C#, showing code like I’d expect:

public void ExampleMethod(int required, 
    string optionalstr = "default string", 
    int optionalint = 10)

Ok, but it also says:

You can also declare optional
parameters by using the .NET
OptionalAttribute class.
OptionalAttribute parameters do not
require a default value.

I read MSDN’s OptionalAttribute page, and done searches online (which shows lots of people claiming OptionalAttribute parameters can’t be consumed by C# — I’m guessing these comments were made before C# 4?), but I can’t find the answer to two questions:

If I use OptionalAttribute to define a C# parameter as optional:

  1. what value will be used if I call that method and don’t specify that parameter’s value?
  2. will that value be evaluated at compile time or runtime?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:32:27+00:00Added an answer on May 16, 2026 at 4:32 am

    The rules are this:

    • For parameters of type object, Type.Missing is passed.
    • For other reference types, null is passed.
    • For value types, the default of the value type is passed.
      • For Nullable<T> this means that you will get a Nullable<T> instance which is equal to null (the HasValue property will return false)

    Note that in the case of everything except parameters of type object, it’s the equivalent of default(T).

    I was a little surprised, as the C# 4.0 specification didn’t indicate what the outcome would be, and I’d expect it to be there.

    Also (as indicated by Scott Rippey in the comments), this is evaluated at compile-time, this is not a run-time operation, meaning that if you have calls to this method in other assemblies which are already deployed, and you change the optional value, the default passed to the method will not change unless you compile everything that makes the call against the method in the assembly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See How to get parent process in .NET in managed… May 16, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer Maybe use a try...except block: try: value=parser.getint(section,option) except ValueError: value=parser.get(section,option)… May 16, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer Collect all indices from aiMesh::mFaces in a single buffer. Make… May 16, 2026 at 3:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

MSDN docs state An expression is a fragment of code that can be evaluated
I read some articles in MSDN magazine about new features in ASP.NET AJAX 4.0
MSDN says that you should use structs when you need lightweight objects. Are there
MSDN displays the following for CreatePatternBrush: You can delete a pattern brush without affecting
MSDN says that the function SetDllDirectory() can be used to insert a directory into
MSDN says that a class that would be 16 bytes or less would be
MSDN points out that mutating access to the .NET Dictionary<K,V> type is not thread
MSDN advises that RegisterWindowMessage() function is only used for registering messages to be sent
MSDN provides a digit placeholder example: 1234.5678 (#####) -> 1235 I found this confusing
MSDN states that String.Intern retrieves the system's reference to the specified String and String.IsInterned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.