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. General Programming
  3. C#
  4. can we create object of partial class

can we create object of partial class

Scheduled Pinned Locked Moved C#
5 Posts 5 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.
  • V Offline
    V Offline
    Vivek Vijayan
    wrote on last edited by
    #1

    can we create object of partial class

    This code was posted by me...

    M D T P 4 Replies Last reply
    0
    • V Vivek Vijayan

      can we create object of partial class

      This code was posted by me...

      M Offline
      M Offline
      Mirko1980
      wrote on last edited by
      #2

      Yes, for example, the following code works:

      public partial class Class1
      {
      int i = 10;

      public void Foo()
      {
          Console.WriteLine(i);
      }
      

      }

      static class Program
      {
      static void Main()
      {
      Class1 cl1 = new Class1();
      cl1.Foo();
      }
      }

      1 Reply Last reply
      0
      • V Vivek Vijayan

        can we create object of partial class

        This code was posted by me...

        D Offline
        D Offline
        DoctorMick
        wrote on last edited by
        #3

        Yes but it will create an instance of all parts of the class (if that makes sense) and not just one of the partial implementations.

        1 Reply Last reply
        0
        • V Vivek Vijayan

          can we create object of partial class

          This code was posted by me...

          T Offline
          T Offline
          Thomas Weller 0
          wrote on last edited by
          #4

          What exactly do you mean? The partial keyword means nothing but: the source code for a certain class can be found in more than one ASCII file. It's all about text... So a partial class is just another class, there is nothing like 'partial' in the IL code that the compiler generates. And of course you can instantiate a normal class... Regards Thomas

          www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
          Programmer - an organism that turns coffee into software.

          1 Reply Last reply
          0
          • V Vivek Vijayan

            can we create object of partial class

            This code was posted by me...

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            The partial keyword is just a hint to the compiler. Once the code is compiled, it is no longer partial.

            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