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
pagefault pagefault
NA
12
10.8k
[solved] scope of private variables
Feb 23 2012 12:23 PM
This code works. I'm not sure it should. It's a standard overwriting of the Equals method. The part that puzzles me is the field 'unitId'. It's a *private* field.
That 'this.unitId' works is no mystery. It's part of the same object. But why doesn't the 'otherTUI.unitId' give a compilation error, let alone work ? It belongs to another (hence 'otherTUI) instantiated object and it is 'private' ? Should it not be out of scope ?
Does the act of casting make it come into scope '(TransportUnitInfo) obj'?
public class TransportUnitInfo
{
private int unitId;
public override bool Equals (object obj)
{
/*
if (obj == null)
return false;
if (!this.GetType().Equals(obj.GetType()))
return false;
*/
TransportUnitInfo otherTUI = (TransportUnitInfo) obj;
return this.unitId == otherTUI.unitId;
}
}
Commented out boilerplate, to not let it distract, it needs to be there but thats not what I'm wondering about.
Reply
Answers (
3
)
back end
resizing controls dynamically