473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Comparing a Class with a Base

If I have a class foo:

public class foo
{
string baseString;

public foo()
{
baseString = "";
}

public foo(string s)
{
baseString = s;
}

public static bool operator==(foo lhs, foo rhs)
{
return lhs.baseString == rhs.baseString;
}
}

And a derived class bar:

public class bar : foo
{
int x;

public bar()
{
x = 0;
}

public bar (string s, int y) : base(s)
{
x = y;
}

public static bool operator==(bar lhs, bar rhs)
{
// WHAT GOES IN HERE?
}
}

Do I have to do comparisons on both member variables? Or can I somehow
pass off the string part to foo to compare? What is the syntax?

Thanks,

-- Rick
Nov 15 '05 #1
2 917
public static bool operator==(bar lhs, bar rhs)
{
// WHAT GOES IN HERE?
}
}

Do I have to do comparisons on both member variables? Or can I somehow
pass off the string part to foo to compare? What is the syntax?


You could do

return (foo)lhs == (foo)rhs && lhs.x == rhs.x;

if that's what you're looking for.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
In article <ey**************@TK2MSFTNGP12.phx.gbl>,
ma********************@mvps.org says...
public static bool operator==(bar lhs, bar rhs)
{
// WHAT GOES IN HERE?
}

You could do

return (foo)lhs == (foo)rhs && lhs.x == rhs.x;


That's exactly what I was looking for, Mattias, thank you!

-- Rick
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tony Johansson | last post by:
Hello! If you compare an abstract baseclass and an Interface and you only look at the datamembers what exactly is that differ or is the same. For example can you have datamember in both or just...
3
by: Chris Blanco | last post by:
I am building a Dynamic assembly loader which will scan and monitor a directory, when a new assembly gets placed in that directory it will examine the directory to see if there is a class that is...
3
by: Simon Harvey | last post by:
Hi all, I hope someone can help me with the following: I have a number of usercontrols that I've made which provides certain audit functions for any data inserted into it. Each audit control...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
3
by: s99999999s2003 | last post by:
hi i wrote some code to compare 2 files. One is the base file, the other file i got from somewhere. I need to compare this file against the base, eg base file abc def ghi eg another file
9
by: subramanian100in | last post by:
Suppose we have char *a = "test message" ; Consider the comparison if (a == "string") ..... Here "string" is an array of characters. So shouldn't the compiler
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
5
by: saneman | last post by:
I have a function: int F(double a) { if (a = =1.0) { return 22; } return 44; }
6
by: hanna88 | last post by:
in the test core i was given 2 objects eg: base a; base b (parameter); both have the same member functions so how to differentiate between these two objects.given that a test core of ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.