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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:39:48+00:00 2026-06-08T10:39:48+00:00

Say I have two methods, one calls the other. The second method has code

  • 0

Say I have two methods, one calls the other. The second method has code that will generate a compile time error. Since it’s not called, why does the compiler still bother to process it?

void method1()
{
    var i = 1;
    //method2();
}

void method2()
{
    int i = "2";
}
  • 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-06-08T10:39:50+00:00Added an answer on June 8, 2026 at 10:39 am

    You can’t be sure that someone else won’t call that method at runtime using reflection. Your code MUST compile or it’s not valid code – if it’s never used… comment it out!

    To expand on this:

    Basically at compile time you are strongly typed – .NET will type check everything to ensure that what you are trying to do is legal, however, you can still throw exceptions at run time due to null references, bad casts etc etc.

    Reflection is a component of the .NET framework that allows a developer to inspect the properties/fields/methods etc of an assemblies types via the assembly metadata

    Reflection allows runtime type discovery and inspection of these types, it also allows invocation of methods/properties and modification of fields etc. (You can even create new generic types at runtime or completely new types altogether).

    In other words, you can’t guarantee that code you think won’t be called, isn’t called somewhere else at some point. For reflection to be possible, every bit of code needs to be valid and compilable

    Whether that code will succeed at runtime is another story – but that’s why we have exception handling.

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

Sidebar

Related Questions

Let's say I have a structure named vertex with a method that adds two
Say I have two interfaces, IFeaturesA, IFeaturesB. IFeaturesA has a set of signature methods.
lets say I have two methods in my controller to support both json and
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
Say we have two activities, Activity1 and Activity2. In Activity1's onClick() method, we have
Say I have two Java apps that I wrote: Ping.jar and Pong.jar and they
Say I have two classes and have a requirement that the primary key property
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
Say I have an overloaded extension method with the following two signatures: public static
Lets say that I have two different types of RelativeLayouts. That is to say

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.