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 733139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:13:21+00:00 2026-05-14T07:13:21+00:00

I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies

  • 0

I have a function defined like this:

public static void ShowAbout(Point location, bool stripSystemAssemblies = false, bool reflectionOnly = false)

This flags CA1026 “Replace method ‘ShowAbout’ with an overload that supplies all default arguments”. I can’t do Point location = new Point(0, 0) or Point location = Point.Empty because neither are compile time constants and therefore cannot be the default values for that function argument. So the question is, how does one go about specifying default argument values for structures? If it can’t be done, likely I’ll go for suppressing CA1026 in source with whatever justification someone here gives.

  • 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-14T07:13:21+00:00Added an answer on May 14, 2026 at 7:13 am

    You can do this:

    public static void ShowAbout(Point location = new Point(), 
        bool stripSystemAssemblies = false,
        bool reflectionOnly = false)
    

    From the C# 4 spec, section 10.6.1:

    The expression in a default-argument
    must be one of the following:

    • a constant-expression
    • an expression of the form new S() where S is a value type
    • an expression of the form default(S) where S is a value type

    So you could also use:

    public static void ShowAbout(Point location = default(Point),
        bool stripSystemAssemblies = false,
        bool reflectionOnly = false)
    

    EDIT: If you wanted to default to a value other than the point (0, 0), it’s worth knowing about another trick:

    public static void ShowAbout(Point? location = null
        bool stripSystemAssemblies = false,
        bool reflectionOnly = false)
    {
        // Default to point (1, 1) instead.
        Point realLocation = location ?? new Point(1, 1);
        ...
    }
    

    This would also let callers explicitly say, “you pick the default” by passing in null.

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

Sidebar

Related Questions

I have a template class defined in a header file like this. Here I
When I define progress dialog functions such as public static void showLoadingBar(Context context) {
I doubt this is possible but what I would like to do is have
I have a class Yarl in my code with a member function refresh that
I have an extended BaseAdapter in a ListActivity: private static class RequestAdapter extends BaseAdapter
What I have is a class with static properties that I want to use
I would like to better understand how to use static field an method in
I have two console apps, Query and Update, that share some functionality. I wanted
How would I test my mappers in Zend_Db? Each of my model will have
I have a simple core class that is being used for core functions to

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.