Part 11: C# Tutorial – Methods in C#

We will cover following points in this article

1. Why methods
2. Method Signature
3. Difference between static and instance methods

     Why Methods
1. Methods are also called as functions.
2. Method is a code block that contains a series of statements and used to define the
    behavior of a class.
3. Methods are extremely useful because they allow you to separate your logic into different
    units. You can pass information to methods, have it perform one or more statements, and
    retrieve a return value. 

4. Methods make application maintenance easier.

Methods Signature

<
attributes>
<accessmodifiers> <return-type> <method-name> (<parameters>)
{
       //method body
}
<access modifiers> à public, private, protected, internal, protected internal
<return-type>          à void or any valid data type
<method-name>     à can be any meaningful name except reserved keyword
<parameters>         à are optional

Static vs Instance methods
1. Static methods are declared using static modifier. Static methods are invoked using the         class name.
2.  Instance methods are declared without using the static modifier. Instance methods are         invoked using the instance of the class.
3. A static method cannot access non-static class level members.
4. Instance methods can access static fields.
5. If a method is declared as static then only one definition of the static method exists in the       memory. Multiple instances/objects of a single class can invoke only one definition of the       static methods but each objects will have its own separate instance methods.



3 thoughts on “Part 11: C# Tutorial – Methods in C#

  1. Freddy Klingberg

    Hi There! We are searching for some people that are interested in from working their home on a full-time basis. If you want to earn $200 a day, and you don’t mind writing some short opinions up, this is the perfect opportunity for you! Simply check out the link here NOW!

  2. http://theinternationalcenter.org

    It has not till hell freezes over been easier to choose between the
    transportation services, as all bloke opinions and testimonials are gathered in identical see fitted you to pick the best.
    Escape bad je sais quoi and as a result bad experience by means of consulting any transmission website reviews.

    Entirely written testimonials choice example you by the process of
    selecting the one and only rendering checking that will spasmodically your
    needs.

  3. http://booktranslationservices.com

    Businesses are erasing the boundaries between nations and as
    a outcome, communication compete with the requisite portion in expanding your reach as entrepreneur.

    Communication, in this quandary, is the genius to convert between any
    cant pair there is and the rewrite services increase has made it steady easier.
    You valid from to coerce sure-fire the retinue you trust your
    rendition offers adequate help, which can be verified through checking the reviews
    of the particular one.

Leave a Reply

Your email address will not be published. Required fields are marked *