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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:14:59+00:00 2026-05-24T08:14:59+00:00

At page.170 of ‘CLR via C#’: public sealed class Program { public Int32 GetFive()

  • 0

At page.170 of ‘CLR via C#’:


public sealed class Program {
    public Int32 GetFive() { return 5; }
    public static void Main() {
       Program p = null;
       Int32 x = p.GetFive(); // In C#, NullReferenceException is thrown
    }
}

Theoretically, the code above is fine. Sure, the variable p is null, but when calling a nonvirtual
method (GetFive), the CLR needs to know just the data type of p, which is Program. If
GetFive did get called, the value of the this argument would be null. Since the argument
is not used inside the GetFive method, no NullReferenceException would be thrown.


Pardon my stupid. I remember that CLR locate really method code by ‘this’ which always implictly appares at the first argument in method delcare, why it says ‘when calling a nonvirtual
method (GetFive), the CLR needs to know just the data type of p’ ?

  • 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-24T08:15:01+00:00Added an answer on May 24, 2026 at 8:15 am

    The CLR doesn’t do null checks for non-virtual methods. Basically, if a method is called with the call instruction, the CLR does not check for a null this pointer. In contrast, the callvirt instruction always checks for nullity. However, C# emits the callvirt instruction whether or not the method is virtual.

    What the passage is saying is that if the C# compiler emitted the more semantically appropriate call instruction rather than callvirt instruction for non-virtual methods, then the code in question would not throw a NullReferenceException. As I recall, the compiler team decided to almost always emit the callvirt instruction because it handled versioning better (also the JIT can optimize a callvirt into a call).

    See http://www.pvle.be/tag/clr/

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

Sidebar

Related Questions

I've got a page: <phone:PhoneApplicationPage x:Class=VKClient.ConversationListPage xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:phone=clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone xmlns:shell=clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 FontFamily={StaticResource PhoneFontFamilyNormal}
I'm trying to create a aspx page that return Image/Png from a chartDirector Here
I have one static page displaying result of an event as given below. <StackPanel
I'm using the code from this page http://jsfiddle.net/gnQUe/170/ jquery slide toggle as a form
Page of the application with the TextBlock and Button, also involved .txt document with
Page 239 of Agile Web Development with Rails instructs us to add the vendor/cache
Page A has a meta refresh to redirect to another page, C , after
Page has menu items that would replace a 'div id=foo_(current menu item)' with 'div
Page in question: http://phwsinc.com/our-work/one-rincon-hill.asp In IE6-8, when you click the left-most thumbnail in the
page contents: aa<b>1;2'3</b>hh<b>aaa</b>.. .<b>bbb</b> blabla.. i want to get result: 1;2'3aaabbb match tag is

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.