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. about methods

about methods

Scheduled Pinned Locked Moved C#
question
8 Posts 6 Posters 1 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
    chinnivinay
    wrote on last edited by
    #1

    what is virtual method,dynamic method,static method

    C J L B 4 Replies Last reply
    0
    • C chinnivinay

      what is virtual method,dynamic method,static method

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

      What is homework ? What is google ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • C chinnivinay

        what is virtual method,dynamic method,static method

        J Offline
        J Offline
        jdkulkarni
        wrote on last edited by
        #3

        Virtual methods are those methods which you want to call using base class object with derived class reference.

        namespace SomeCorpProject
        {
        public class BaseBusinessObject
        {
        public BaseBusinessObject()
        {
        }

            public virtual void VirtualMethod()
            {
                Console.WriteLine("Virtual method");
            }
        
            public override string ToString() 
            {
                return "BaseBusinessObject";
            }       
        }
        

        }

        namespace SomeCorpProject
        {
        public class Capacitor : BaseBusinessObject
        {
        public Capacitor()
        {
        }

            public static void StaticMethod()
            {
                Console.WriteLine("I am static, no need to create object of class.");
            }
        
            public override void VirtualMethod()
            {
                Console.WriteLine("In derived virtual method");
                base.VirtualMethod();
            }
        
            public override string ToString() 
            {
                return "Capacitor";
            }
        }
        

        }

        namespace SomeCorpProject
        {
        class Class1
        {
        [STAThread]
        static void Main(string[] args)
        {
        BaseBusinessObject bizObj = new Capacitor();
        bizObj.VirtualMethod();
        Capacitor.StaticMethod();
        System.Console.WriteLine(bizObj.ToString());
        }
        }
        }

        The above code will explain most of the concepts. Static methods are those methods for which object of the class need not to be created. They share the common info across all class objects. They are loaded in the memory before class gets loaded. Dynamic methods? I do not have idea. But I think they might be instance methods. i.e. you should create an object of the class to call these methods. :)

        Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET

        C 1 Reply Last reply
        0
        • C chinnivinay

          what is virtual method,dynamic method,static method

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Just adding a little, virtual methods can be overwritten in a derived class (by using overwrite keyword) but is not mandatory. Also you can have a method with the same name as the one in a parent class and hide it with a technique called shadowing (by using new keyword).

          1 Reply Last reply
          0
          • J jdkulkarni

            Virtual methods are those methods which you want to call using base class object with derived class reference.

            namespace SomeCorpProject
            {
            public class BaseBusinessObject
            {
            public BaseBusinessObject()
            {
            }

                public virtual void VirtualMethod()
                {
                    Console.WriteLine("Virtual method");
                }
            
                public override string ToString() 
                {
                    return "BaseBusinessObject";
                }       
            }
            

            }

            namespace SomeCorpProject
            {
            public class Capacitor : BaseBusinessObject
            {
            public Capacitor()
            {
            }

                public static void StaticMethod()
                {
                    Console.WriteLine("I am static, no need to create object of class.");
                }
            
                public override void VirtualMethod()
                {
                    Console.WriteLine("In derived virtual method");
                    base.VirtualMethod();
                }
            
                public override string ToString() 
                {
                    return "Capacitor";
                }
            }
            

            }

            namespace SomeCorpProject
            {
            class Class1
            {
            [STAThread]
            static void Main(string[] args)
            {
            BaseBusinessObject bizObj = new Capacitor();
            bizObj.VirtualMethod();
            Capacitor.StaticMethod();
            System.Console.WriteLine(bizObj.ToString());
            }
            }
            }

            The above code will explain most of the concepts. Static methods are those methods for which object of the class need not to be created. They share the common info across all class objects. They are loaded in the memory before class gets loaded. Dynamic methods? I do not have idea. But I think they might be instance methods. i.e. you should create an object of the class to call these methods. :)

            Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET

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

            jdkulkarni wrote:

            Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET

            Wow - is that worth something in parts of the world ? I wouldn't have given the answer, because all you're doing is teaching this person to not do their own homework. I hope he ends up working in the cubicle next to you and not near me.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            E 2 Replies Last reply
            0
            • C chinnivinay

              what is virtual method,dynamic method,static method

              B Offline
              B Offline
              Bhupi Bhai
              wrote on last edited by
              #6

              Have you heard of MSDN ?? Regards, Bhupi Bhai.

              1 Reply Last reply
              0
              • C Christian Graus

                jdkulkarni wrote:

                Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET

                Wow - is that worth something in parts of the world ? I wouldn't have given the answer, because all you're doing is teaching this person to not do their own homework. I hope he ends up working in the cubicle next to you and not near me.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                E Offline
                E Offline
                ednrgc
                wrote on last edited by
                #7

                Brainbench rules!!! :rolleyes: :rolleyes: :rolleyes:

                1 Reply Last reply
                0
                • C Christian Graus

                  jdkulkarni wrote:

                  Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET

                  Wow - is that worth something in parts of the world ? I wouldn't have given the answer, because all you're doing is teaching this person to not do their own homework. I hope he ends up working in the cubicle next to you and not near me.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                  E Offline
                  E Offline
                  ednrgc
                  wrote on last edited by
                  #8

                  As far as hand feeding, I couldn't agree more. Unfortunately, I think I do sit next to him :omg: :-D

                  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