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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:40:03+00:00 2026-05-13T10:40:03+00:00

I understand partial methods can be used to split the definition of a method

  • 0

I understand partial methods can be used to split the definition of a method across multiple files. I’m curious though if it’s permissible to have each definition of a method across multiple files contain code?

For example, say I have a method private partial void Foo(). Let’s say I’ve got it defined in file A and file B. Can both instances have code contained in the method, or just one or the other? I guess I’d be surprised if this were permitted.

  • 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-13T10:40:03+00:00Added an answer on May 13, 2026 at 10:40 am

    No, you can’t. If you could, when you call Foo(), which code would execute first? If both versions were dealing with (and modifying) global state, it would be very important to know the order of execution.

    Anyway, it makes no sense. So no, you can’t.

    ##Nasty example 1
    As a simple example of the potential nastiness of the erratic behavior emerging from such a possibility, suppose you could, and suppose you had the following code:

    public partial class MyClass {
        private int count = 0;
        public partial void NastyMethod() {
            count++;
        }
    }
    
    public partial class MyClass {
        public partial void NastyMethod() {
            Console.WriteLine(count);
        }
    }
    

    When you call NastyMethod(), what value would it print? No sense!

    ##Nasty example 2

    Now another strange problem. What to do with parameters? And return values?

    public partial class MyClass2 {
        public partial bool HasRealSolution(double a, double b, double c) {
            var delta = b*b - 4*a*c;
            return delta >= 0;
        }
    }
    
    public partial class MyClass2 {
        public partial bool HasRealSolution(double a, double b, double c) {
            return false;
        }
    }
    

    And now, how could one possibly give a sense to this code? Which return should we consider after calling HasRealSolution(1, 2, 1)? How is it ever conceivable to have 2 different, simultaneous, return values* for a single method? We are not dealing with nondeterministic finite automata!

    To those who would impose that in this hypothetical world my inexistent partial methods should be void, replace the returns with setting a value on some private field to that class. The effect is almost the same.

    * Note that what I’m talking here is not a single return value composed of two values, such as a Tuple<T1, T2>. I’m talking here about TWO return values. (???)

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

Sidebar

Ask A Question

Stats

  • Questions 279k
  • Answers 279k
  • 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 Your eventhandler for the OnMouseMove event should recieve a MouseEventArgs… May 13, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer if your webhelpers version is 1.0b4 or above, secure_form is… May 13, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer There's probably a confusion between private and 3rd-party APIs. Private… May 13, 2026 at 3:20 pm

Related Questions

I have couple questions regarding some C++ rules. Why am I able to call
That's it. It's a dumb dumb (embarrassing!) question, but I've never used C# before,
I have a class e.g. DerivedClass that inherits from a base class e.g. BaseClass.
I need to set a single property in a jQuery command using a value
I have a WPF dll that contains a number of Window classes and exposes

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.