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

  • SEARCH
  • Home
  • 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 154819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:02:48+00:00 2026-05-11T10:02:48+00:00

What value do you think named and default parameters will add in C#.Net 4.0?

  • 0

What value do you think named and default parameters will add in C#.Net 4.0?

What would be a good use for these (that hasn’t already been achieved with overloading and overriding)?

  • 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. 2026-05-11T10:02:48+00:00Added an answer on May 11, 2026 at 10:02 am

    It can make constructors simpler, especially for immutable types (which are important for threading) – see here for a full discussion. Not as nice as it should be perhaps, but nicer than having lots of overloads. You obviously can’t use object initializers with immutable objects, so the usual:

    new Foo {Id = 25, Name = 'Fred'} 

    isn’t available; I’ll settle for:

    new Foo (Id: 25, Name: 'Fred') 

    This can be extended to the general idea of simplifying overloads, but in most cases I’d prefer overloads that advertise the legal combinations. Constructors are a bit different, IMO, since you are just (typically) defining the initial state.

    The COM side of things is also important to a lot of people, but I simply don’t use much COM interop – so this isn’t as important to me.


    Edit re comments; why didn’t they just use the same syntax that attributes use? Simple – it can be ambiguous with other members / variables (which isn’t an issue with attributes); take the example:

    [XmlElement('foo', Namespace = 'bar')] 

    which uses one regular parameter (to the ctor, ‘foo’), and one named assignment. So suppose we use this for regular named arguments:

    SomeMethod('foo', SecondArg = 'bar'); 

    (which could also be a constructor; I’ve used a method for simplicity)

    Now… what if we have a variable or a property called SecondArg? This would be ambiguous between using SecondArg as a named argument to SomeMethod, and assigning ‘bar’ to SecondArg, and passing ‘bar’ as a regular argument.

    To illustrate, this is legal in C# 3.0:

        static void SomeMethod(string x, string y) { }     static void Main()     {         string SecondArg;         SomeMethod('foo', SecondArg = 'bar');     } 

    Obviously, SecondArg could be a property, field, varialble, etc…

    The alternative syntax doesn’t have this ambiguity.


    Edit – this section by 280Z28: Sorry for adding this here, but it’s not really a unique answer and it’s too long for the comments and includes code. You hinted at the ambiguity but your example didn’t highlight the deciding case. I think the example you gave points out something that could be confusing, but the required {} around object initializers prevents an underlying syntactical ambiguity. My explanation for the following code is embedded as the multi-line block comment.

    [AttributeUsage(AttributeTargets.Class)] public sealed class SomeAttribute : Attribute {     public SomeAttribute() { }      public SomeAttribute(int SomeVariable)     {         this.SomeVariable = SomeVariable;     }      public int SomeVariable     {         get;         set;     } }  /* Here's the true ambiguity: When you add an attribute, and only in this case  * there would be no way without a new syntax to use named arguments with attributes.  * This is a particular problem because attributes are a prime candidate for  * constructor simplification for immutable data types.  */  // This calls the constructor with 1 arg [Some(SomeVariable: 3)] // This calls the constructor with 0 args, followed by setting a property [Some(SomeVariable = 3)] public class SomeClass { } 

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

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is possible (if C_KEY_MAKER's random behaviour is based on… May 12, 2026 at 12:18 am
  • Editorial Team
    Editorial Team added an answer I typically use range to swap out text when needed.… May 12, 2026 at 12:18 am
  • Editorial Team
    Editorial Team added an answer I found that putting wsgi in daemon mode works. Not… May 12, 2026 at 12:18 am

Related Questions

I have a method with an out parameter that tries to do a type
I have a page that visually has two fields right on top of each
I edited the question after David Hanak's answer (thanks btw!). He helped with the
I am running a Tomcat application, and I need to display some time values.

Trending Tags

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

Top Members

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.