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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:35:09+00:00 2026-05-31T18:35:09+00:00

I apologise if this has been asked before or if it’s now answerable. I’m

  • 0

I apologise if this has been asked before or if it’s now answerable.

I’m working with a big code base (most of it was written by another Software Engineer before I started work on it, standard affair). I’ve added quite a lot of code to this project, most of it has been wrapping existing methods into objects/libraries for ease of reuse. By wrapped, I mean that I’ve copied them into a new object/library, edited them to make them work as standalone objects or libraries (where applicable) and called/instantiated them where appropriate in the original code base.

For instance, instead of a massive method (foo) that provides some one time function being included in one of the .cs files for the main exe, I’ve wrapped it up in it’s own class and separated it, so that it can (theoretically) be used in other projects or different parts of the solution.

IE going from this:

/* somewhere in Main */
void Main ()
{
...
foo (arg1, arg2, arg3)
...
}

foo (arg1, arg2, arg3)
{
//some massive functionality
}

to this:

/* somewhere in Main or any other part of the code base */
Foo myFoo = new Foo (arg1, arg2, arg3);
myFoo.DoSomething();

today, I’ve started looking through the code base and commenting out all of the old methods (the one’s that I’ve wrapped into objects/libraries) in an effort figure out which of them I can remove from the original code base. I’m using version control software, and I’m doing them a few at a time, then re-compiling and performing some testing to check that I’ve not broken anything.

My question is this:
When I compile, is the C# compiler (using version 3.5) smart enough that it wont include methods/functions/objects/libraries that never get called, instantiated or used?

I’m still going to tiding up/clean out the now deprecated methods/functions, but I’m just wondering whether the compiler can produce outputs that don’t contain these methods/functions.

TL;DR: if I have the following Main.cs

/*using statements here*/
public void Main ()
{
  foo();
}

foo ()
{
  /*Some commands*/
}

bar()
{
  /*Never called*/
}

Does my compiled output contain any references to bar?

  • 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-31T18:35:10+00:00Added an answer on May 31, 2026 at 6:35 pm

    The C# compiler will include all methods, even those that are never called, and even if they are private.

    So yes, the compiled output defines the method bar, and its body is compiled and present in your binary.

    This means that you can break code by just removing a method, even if the result compiles: that method could be invoked by reflection only. So you’re right about also doing the testing afterwards.

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

Sidebar

Related Questions

I apologise if this has been asked before but I can't find the info
I apologise if this question has already been asked on here before but I
Apologies if this is too ignorant a question or has been asked before. A
Apologies if this has been asked before (I couldn't find the answer anywhere), but
I apologize if this has been asked before, but I haven't quite found the
First, I apologize if this has been asked before - indeed I'm sure it
Apologies if this question has been asked before, I couldn't find anything similar. I
Ok, first off, I applogize if this question has been asked before, I've spent
I apologize if this question has been asked before, but my case is a
I apologize in advance if this has been asked before, but I haven't been

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.