Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
Boxing Mystery in Overloaded and Overrided Method
angwin
17y
1.9k
1
Reply
Hello!
I have a class with two overloaded methods
int Foo(int i) { Foo(i); }
int Foo(int? i) { }
First method call leads to StackOverflowException. It is OK.
Change the code so that the base class contains virtual method "int Foo(int i)" and inhereted class declares
override
int Foo(int i) { Foo(i); }
int Foo(int? i) { }
After calling the first method, a mystery occurs - the value-type argument "i" is boxed and the second method is called instead of repeating the first one. Why? Articel with complete source code and its IL-code is here:
http://dotnet-enthusiast.blogspot.com/2007/09/boxing-mystery-in-overloaded-and.html
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
IsNumeric
NP51 Carriage return \r in a program