Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. ARGH !!!!!

ARGH !!!!!

Scheduled Pinned Locked Moved The Lounge
csharp
17 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #1

    There is no operator= overloading in C#. ARGH !!!!!! Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

    N M N 3 Replies Last reply
    0
    • C Christian Graus

      There is no operator= overloading in C#. ARGH !!!!!! Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      Christian Graus wrote: There is no operator= overloading in C#. ARGH !!!!!! Use a copy constructor. They both achieve the same thing I guess. Nish


      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

      C 1 Reply Last reply
      0
      • N Nish Nishant

        Christian Graus wrote: There is no operator= overloading in C#. ARGH !!!!!! Use a copy constructor. They both achieve the same thing I guess. Nish


        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Nishant S wrote: Use a copy constructor. They both achieve the same thing I guess. Not quite, but actually close enough for my purposes - thanks. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

        D 1 Reply Last reply
        0
        • C Christian Graus

          There is no operator= overloading in C#. ARGH !!!!!! Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

          M Offline
          M Offline
          Martin Marvinski
          wrote on last edited by
          #4

          Christian Graus wrote: There is no operator= overloading in C#. ARGH !!!!!! That's to be expected because C# is modeled after Java, and the designers of Java felt that there really wasn't a need for it except in the case of strings, which they implemented as part of Java...

          A J E 3 Replies Last reply
          0
          • C Christian Graus

            Nishant S wrote: Use a copy constructor. They both achieve the same thing I guess. Not quite, but actually close enough for my purposes - thanks. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

            D Offline
            D Offline
            Davy Mitchell
            wrote on last edited by
            #5

            Woah - so C# can pass objects by value? Sorry just downloaded the SDK and I am a bit behind! Davy http://www.LateDecember.com

            C 1 Reply Last reply
            0
            • D Davy Mitchell

              Woah - so C# can pass objects by value? Sorry just downloaded the SDK and I am a bit behind! Davy http://www.LateDecember.com

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Structs are passed by value, classes by reference. I wanted operator= to do a deep copy for an internal class. But I cannot do operator= even if it was a struct. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

              J 1 Reply Last reply
              0
              • C Christian Graus

                There is no operator= overloading in C#. ARGH !!!!!! Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

                N Offline
                N Offline
                NormDroid
                wrote on last edited by
                #7

                and no templates X| X| X| Normski. - the next bit of code is self modifying ... jmp 0xCODE

                A 1 Reply Last reply
                0
                • M Martin Marvinski

                  Christian Graus wrote: There is no operator= overloading in C#. ARGH !!!!!! That's to be expected because C# is modeled after Java, and the designers of Java felt that there really wasn't a need for it except in the case of strings, which they implemented as part of Java...

                  A Offline
                  A Offline
                  Alexandru Savescu
                  wrote on last edited by
                  #8

                  In Java you cannot overload any operator, not just =. That's one of the reasons I find it weaker than C++. Best regards, Alexandru Savescu

                  P 1 Reply Last reply
                  0
                  • A Alexandru Savescu

                    In Java you cannot overload any operator, not just =. That's one of the reasons I find it weaker than C++. Best regards, Alexandru Savescu

                    P Offline
                    P Offline
                    Pankaj Singh
                    wrote on last edited by
                    #9

                    just because one thing u should not judge a lang to be weak Every body knows that nothing is as powerful C++ certainly not JAVA...

                    J 1 Reply Last reply
                    0
                    • C Christian Graus

                      Structs are passed by value, classes by reference. I wanted operator= to do a deep copy for an internal class. But I cannot do operator= even if it was a struct. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

                      J Offline
                      J Offline
                      James T Johnson
                      wrote on last edited by
                      #10

                      For a deep copy, the ".NET way" is to implement ICloneable or as Nish suggested, a copy constructor. I recall talking about how to implement a strongly-typed version recently in the C# forum; maybe it was in our thread about casting. Anyway, I think the reason for this is because it the assignment is actually between references not the actual class. See below for a code comparison illustrating why this is true. C# MyClass pMC = GetMyClassPointer(); MyClass pMC2 = pMC; M/C++ MyClass* pMC = GetMyClassPointer(); MyClass* pMC2 = pMC; Assignment also behaves the same with structs except that it performs a shallow copy via the MemberwiseClone method (which unfortunately cannot be overriden). James "Java is free - and worth every penny." - Christian Graus [Edit: old habits die hard, thats all I'll say about my edit :-O]

                      C 1 Reply Last reply
                      0
                      • P Pankaj Singh

                        just because one thing u should not judge a lang to be weak Every body knows that nothing is as powerful C++ certainly not JAVA...

                        J Offline
                        J Offline
                        James T Johnson
                        wrote on last edited by
                        #11

                        Pankaj Singh wrote: just because one thing u should not judge a lang to be weak He didn't; he said it was one of the reasons, personally I agree with him. James "Java is free - and worth every penny." - Christian Graus

                        1 Reply Last reply
                        0
                        • N NormDroid

                          and no templates X| X| X| Normski. - the next bit of code is self modifying ... jmp 0xCODE

                          A Offline
                          A Offline
                          Alexandru Savescu
                          wrote on last edited by
                          #12

                          True! :rolleyes: :rolleyes: Best regards, Alexandru Savescu

                          1 Reply Last reply
                          0
                          • J James T Johnson

                            For a deep copy, the ".NET way" is to implement ICloneable or as Nish suggested, a copy constructor. I recall talking about how to implement a strongly-typed version recently in the C# forum; maybe it was in our thread about casting. Anyway, I think the reason for this is because it the assignment is actually between references not the actual class. See below for a code comparison illustrating why this is true. C# MyClass pMC = GetMyClassPointer(); MyClass pMC2 = pMC; M/C++ MyClass* pMC = GetMyClassPointer(); MyClass* pMC2 = pMC; Assignment also behaves the same with structs except that it performs a shallow copy via the MemberwiseClone method (which unfortunately cannot be overriden). James "Java is free - and worth every penny." - Christian Graus [Edit: old habits die hard, thats all I'll say about my edit :-O]

                            C Offline
                            C Offline
                            Christian Graus
                            wrote on last edited by
                            #13

                            Yes, I must admit that on reflection ( no pun intended ), operator = is a bad idea, because then you'd have no idea if you were getting a shallow copy or a deep one. Tell me about ICloneable ? It returns an Object, right ? I'm still pretty annoyed about the whole const thing though. I should put it in my sig. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

                            J 2 Replies Last reply
                            0
                            • M Martin Marvinski

                              Christian Graus wrote: There is no operator= overloading in C#. ARGH !!!!!! That's to be expected because C# is modeled after Java, and the designers of Java felt that there really wasn't a need for it except in the case of strings, which they implemented as part of Java...

                              J Offline
                              J Offline
                              Jorgen Sigvardsson
                              wrote on last edited by
                              #14

                              Nope. operator= is a lowly shallow assignment in Java too. You're probably thinking of operator+ for string concatenation. FreeBSD is sexy. Getting closer and closer to actually submit an article...

                              1 Reply Last reply
                              0
                              • M Martin Marvinski

                                Christian Graus wrote: There is no operator= overloading in C#. ARGH !!!!!! That's to be expected because C# is modeled after Java, and the designers of Java felt that there really wasn't a need for it except in the case of strings, which they implemented as part of Java...

                                E Offline
                                E Offline
                                Eddie Velasquez
                                wrote on last edited by
                                #15

                                Martin Marvinski wrote: That's to be expected because C# is modeled after Java, and the designers of Java felt that there really wasn't a need for it except in the case of strings, which they implemented as part of Java... There's no operator overloading in Java. And C# isn't only modeled after Java it has stronger roots in C++ (than Java that is)


                                All of my opinions are correct, even when reality makes the mistake of disagreeing with me.
                                ASP.NET can never fail as working with it is like fitting bras to supermodels - it's one pleasure after the next - David Wulff

                                1 Reply Last reply
                                0
                                • C Christian Graus

                                  Yes, I must admit that on reflection ( no pun intended ), operator = is a bad idea, because then you'd have no idea if you were getting a shallow copy or a deep one. Tell me about ICloneable ? It returns an Object, right ? I'm still pretty annoyed about the whole const thing though. I should put it in my sig. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

                                  J Offline
                                  J Offline
                                  James T Johnson
                                  wrote on last edited by
                                  #16

                                  Christian Graus wrote: ( no pun intended ), har har :-D Christian Graus wrote: Tell me about ICloneable ? It returns an Object, right ? The ICloneable interface has only one member; object Clone(). However you can use a feature of the CLR/C# to hide the interface implementation so that it is only available if specifically requested, this allows you to -- among other things -- have different return types on the methods and properties required by the interface. To do this, simply prepend the name of the member with the name of the interface you are implementing. In the case of ICloneable I think it is best to implement the interface in terms of the strongly-typed version. So that is what I will do below.

                                  public class Foo : ICloneable
                                  {
                                  .....

                                  public Foo Clone()
                                  {
                                  Foo foo = new Foo();

                                  // deep copy the members
                                  
                                  return foo;
                                  

                                  }

                                  // Doesn't need the public modifier since
                                  // it is an interface implementation doing
                                  // so would be redundant
                                  object ICloneable.Clone()
                                  {
                                  return Clone(); // Calls Foo.Clone()
                                  }
                                  }

                                  Now your code will most likely call Foo's public Clone method; where-as type-generic code will first inquire about ICloneable and call its method. This is how strongly typed collections are created so that they can still implement IList et al while maintaining that the collection uses objects when needed. James "Java is free - and worth every penny." - Christian Graus

                                  1 Reply Last reply
                                  0
                                  • C Christian Graus

                                    Yes, I must admit that on reflection ( no pun intended ), operator = is a bad idea, because then you'd have no idea if you were getting a shallow copy or a deep one. Tell me about ICloneable ? It returns an Object, right ? I'm still pretty annoyed about the whole const thing though. I should put it in my sig. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

                                    J Offline
                                    J Offline
                                    James T Johnson
                                    wrote on last edited by
                                    #17

                                    Forgot to reply to this bit :-O Christian Graus wrote: I'm still pretty annoyed about the whole const thing though. I should put it in my sig. This has come up quite a bit on the partitioned DOTNET lists. Currently some of the MS people have been inquiring for feedback and I believe the issues with const have come up. If you check out the DOTNET-CX list archives on July 17 a thread was started about implementing const objects; perhaps something came up there to give you an idea of a work around. James "Java is free - and worth every penny." - Christian Graus

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups