i m studyng property in c#. while writing a program i got some problem. plz try to rectify it. Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prac1_const__prop_
{
class student
{
private string myname;
private int rollno;
//int rollno,phy, chem,maths,eng, hindi;
public string Name;
{
get
{return myname;} // ERROR WHICH I AM GETTING IS: Error 2 Invalid token '{' in class, struct, or interface member declaration C:\Users\ekta\Documents\Visual Studio 2008\Projects\prac1(const, prop)\prac1(const, prop)\Program.cs 17 9 prac1(const, prop)
set {myname= value;}
}
public int Rollno;
{
get{return rollno;}
set{rollno = value;}
}
class Program
{
static void Main(string[] args)
{
student st= new student();
st.myname = "ekta";
st.rollno = 55;
Console.WriteLine(st.myname);
Console.WriteLine(st.rollno)
}
}
}
The errors which i got are:
Sukesh MarlaPosted Aug 10, 2012, 2:28 PM
namespace prac1_const__prop_
{
class student
{
private string myname;
private int rollno;
public string Name//Semic colon removed
{
get
{
return myname;
}
set
{
myname = value;
}
}
public int Rollno//Semic colon removed
{
get
{
return rollno;
}
set
{
rollno = value;
}
}
}//Class Closed Here
class Program
{
static void Main(string[] args)
{
student st = new student();
st.Name = "ekta";//Property Name was not proper so changed
st.Rollno = 55;//Property Name was not proper so changed
Console.WriteLine(st.Name);//Property Name was not proper so changed
Console.WriteLine(st.Rollno);//Semi Colon Added also Property Name was not proper so changed
}
}
}
Hope It Helped. Please Check This is Currect Answer.