.Net Practical 12


Practical : 12
Subject : .Net

Aim : Write a program in C# to create Read-Write, Read only properties & Write only properties.

Source Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dotnet008
{
    class read_only
    {
        private string stu_name, stu_id;
        public string get_name
        {
            get
            {
                return stu_name;
            }
        }
        public string get_id
        {
            get
            {
                return stu_id;
            }
        }
        public void info(string a,string b)
        {
            stu_name = a;
            stu_id = b;
        }
    }
    class write_only
    {
        private string stu_branch;
        public string set_branch
        {
            set
            {
                stu_branch = value;
            }
        }
        public void display_branch()
        {
            Console.WriteLine("stu_branch : {0}", stu_branch);
        }
    }
    class read_write
    {
        private string stu_sub;
        public string sub
        {
            get
            {
                return stu_sub;
            }
            set
            {
                stu_sub = value;
            }
        }
    }
    class pra12
    {
        static void Main(string[] ar)
        {
            read_only ro = new read_only();
            ro.info("pratik boghani", "171230107008");
            Console.WriteLine("stu_name : {0} \nstu_id : {1}", ro.get_name, ro.get_id); //read
            write_only wo = new write_only();
            wo.set_branch = "computer"; //write
            wo.display_branch();
            read_write rw = new read_write();
            rw.sub = "dot-net"; //write
            Console.WriteLine("stu_subject : {0}",rw.sub); //read
            Console.ReadKey();
        }
    }
}
Output : 


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment