Search This Blog

Tuesday, June 24, 2014

Public keyword C# Example

C# > Keywords > public

Public is the most permissive access level. 

It is no restrictions on accessing public members.






Example


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        public class Person
        {
            public string Name;
            public int Age;
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Person p = new Person();
            p.Name = "John";
            p.Age = 35;
        }
    }
}