Monday 30 January 2017

UNDERSTANDING DIFFERENCE BETWEEN TYPES AND TYPE MEMBERS IN C#

DIFFERENCE BETWEEN TYPES AND TYPE MEMBERS IN C#

Types Vs Type Members

In this example Customer is the Type and fields, properties and method are type members.

So, in general classes, structs, enums, interfaces, delegates are called as types and fields, properties, constructors, methods etc.. that normally reside in a type are called  as type members.

In C# there are 5 different access modifiers:
1.Private
2.Protected
3.Internal
4. Protected Internal
5. Public

Type members can have all the access modifiers, where as types can have only 2 (internal , public) of the 5 access modifiers

Note: Using regions you can expand and collapse sections of your code either manually, or using visual studio Edit>Outling > Toggle All Outlining


using System;
using System.IO;

namespace ConsoleApplication4
{
    class Program
    {
        public static void Main()
        {

        }

    }

    public class Customer
    { 
        #region fields
        private int _id;
        private string _firstName;
        private string _lastName;
        #endregion

        #region properties
        public int Id
        {
            get { return _id; }
            set { _id = value; }

        }
        public string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }

        }
        public string LastName
        {
            get { return _lastName;}
            set { _lastName = value; }
        }
        #endregion

        #region methods
        public string GetFullName()
        {
            return this.FirstName + " " + this.LastName;
        }
        #endregion


    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.