Pages

Sunday, 14 October 2012

Write a program in asp.net C# to create read only properties & write only properties i.e public,private.

Write a program in  asp.net C# to create read only properties & write only properties i.e public,private.

Description:
In this post we are going to learn read only properties & write only properties i.e public,private. 

Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace readandwrite
{
    class Program
    {
        static void Main(string[] args)
        {
            select choice = new select();
            choice.name1 = "sizar";
            choice.age1 = 21;
            Console.WriteLine("My Name is: " + choice.name1);
            Console.WriteLine("My Age is:" + choice.age1);
            choice.age1++;
            Console.WriteLine("AGE is Incremented");
            Console.WriteLine("My Name is: " + choice.name1);
            Console.WriteLine("My Age is:" + choice.age1);
            Console.ReadLine();
        }
    }
}
public class select
{
    private String name;
    private int age;
    public String name1
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public int age1
    {
        get
        {
            return age;
        }
        set
        {
            age = value;
        }

    }
}

Demo:


Write a program in  asp.net C# to create read only properties & write only properties i.e public,private.
Write a program in  asp.net C# to create read only properties & write only properties i.e public,private.






No comments:

Post a Comment