TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Administrator
Tech Writer
2.2k
1.5m
Passing Objects by Value
Apr 8 2003 2:59 PM
I am trying to work through an example in a book and have run across something that just doesn't make sense. In the method listed below, I am passing in a object of type Fraction. public override bool Equals(object o) { if (!(o is Fraction)) { return false; } // Console.WriteLine(o.GetType()); return this ==(Fraction) o; } What I don't understand is why the cast in the last line. If I take the cast out I get the following error: 'Possible unintended reference comparison; to get a value comparison, cast the right hand side to type 'ConsoleApplication18.Fraction' If I uncomment the Console.Writeline it tells me 'o' is of type Fraction. In addition, the error message makes it sound like if I cast to Fraction then the value comparison will be ok. But Fraction is an object and therefore a reference type not a value type. Can someone explain this to me.
Reply
Answers (
2
)
C# Programming assignment
How I may receive DataSet with small decimal using remote object ?