473,473 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Class = Class (operator overriding)

ogs
Why it's not possible to override operator "=" in C#? I have Class - Class1
with one property Prop1. For example

Class1 x = new Class1(); x.Prop1 = "this is x";
Class1 y = new Class1(); y.Prop1 = "this is y";
y = x;

now these (x and y) are two variables looking on one object :[ - changing
one object another object is aleready changing

I need a class which will JUST gather a variables from another class (such
as System.String). I'ts important to use exactly "=" operator, not an
property or IConvertible.Convert()

Thanks a lot, sory about english.
Jul 21 '05 #1
1 1236
If I remember "design decision" as it was most often used incorrectly.

It looks like to me you want to do something like :

y=x.Clone();

You can do this by implementing the IClonable interface (IMO it's cleaner
than doing this by using =)

Patrice

--

"ogs" <og*@discussions.microsoft.com> a écrit dans le message de
news:2D**********************************@microsof t.com...
Why it's not possible to override operator "=" in C#? I have Class - Class1 with one property Prop1. For example

Class1 x = new Class1(); x.Prop1 = "this is x";
Class1 y = new Class1(); y.Prop1 = "this is y";
y = x;

now these (x and y) are two variables looking on one object :[ - changing
one object another object is aleready changing

I need a class which will JUST gather a variables from another class (such
as System.String). I'ts important to use exactly "=" operator, not an
property or IConvertible.Convert()

Thanks a lot, sory about english.

Jul 21 '05 #2

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

Similar topics

16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
1
by: Manuel Massing | last post by:
Hi, I was wondering if there is an easy way to keep track of all allocations issued by instances of a specific class and its subclasses (i.e. keep track of memory consumption of the class...
2
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have...
1
by: Marcos Boyington | last post by:
Hey guys, quick question about how C++ designers chose to not implement this, I'm sure there are some people here who can take a better guess at it than I. So, in C++, the only way to prevent...
2
by: franklini | last post by:
hello people i. can anybody help me, i dont know what is wrong with this class. it has something to do with the me trying to override the input output stream. if i dont override it, it works fine....
1
by: ogs | last post by:
Why it's not possible to override operator "=" in C#? I have Class - Class1 with one property Prop1. For example Class1 x = new Class1(); x.Prop1 = "this is x"; Class1 y = new Class1(); y.Prop1...
14
by: Marcus Kwok | last post by:
If I have some class Foo, my standard way for printing it is to overload operator<< as a friend, e.g., class Foo { int i; public: Foo() : i(0) { } friend std::ostream&...
2
by: cfriedalek | last post by:
Sorry for the vague subject. Not sure what the right terminology is. How can I use an instance's data by reference to the instance name, not the instance attribute? OK the question is probably...
19
by: C++Liliput | last post by:
I have a custom String class that contains an embedded char* member. The copy constructor, assignment operator etc. are all correctly defined. I need to create a map of my string (say a class...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.