Get & Set
-
when i declared a method string getName(){return this.name}; string getAddress(){return this.address;}... get appears like blue color its means c# word, then this methods get and set how can i use them or how its use i hope, i can explain good
Dios creo un equipo perfecto a los demas los lleno de extranjeros
-
when i declared a method string getName(){return this.name}; string getAddress(){return this.address;}... get appears like blue color its means c# word, then this methods get and set how can i use them or how its use i hope, i can explain good
Dios creo un equipo perfecto a los demas los lleno de extranjeros
You should use properties for this, e.g.,
public string Address
{
get
{
return this.address;
}
set
{
this.address = value;
}
}Or, just for get.
public string Address
{
get
{
return this.address;
}
}Kevin
-
when i declared a method string getName(){return this.name}; string getAddress(){return this.address;}... get appears like blue color its means c# word, then this methods get and set how can i use them or how its use i hope, i can explain good
Dios creo un equipo perfecto a los demas los lleno de extranjeros
Hello Legolas, Actually
set
&get
both are keyword of C#. You can use it when you define any property for class like...class TimePeriod { private double seconds; public double Hours { get { return seconds / 3600; } set { seconds = value * 3600; } } }
You can get more help from here.
regards, Divyang Mithaiwala System Engineer & Software Developer
-
when i declared a method string getName(){return this.name}; string getAddress(){return this.address;}... get appears like blue color its means c# word, then this methods get and set how can i use them or how its use i hope, i can explain good
Dios creo un equipo perfecto a los demas los lleno de extranjeros
If you want to use get & set you have to use a Property. (Unless you are programming in Java which don't have get & set) It seems like you have two options. 1. To have TWO methods FOR EACH property, of get and set, eg. string getName() { return this.name; } void setName(string NewName) { this.name = NewName; } (Just like in Java) 2. You can use it as a Property (the easyer and more comfort one), eg.:
string Name { get { return this.name; } set { this.name = value; } } and to use it in code: string thisname = obj1.Name; obj1.Name = "My New Name";
(You don't use the "()" in a Property) You can learn a little bit more if you read a little about this chapter. Hope I helped. NaNg.
-
when i declared a method string getName(){return this.name}; string getAddress(){return this.address;}... get appears like blue color its means c# word, then this methods get and set how can i use them or how its use i hope, i can explain good
Dios creo un equipo perfecto a los demas los lleno de extranjeros
using System; class Circle { public int X { get { return(x); } set { x = value; // draw the object here. } } int x; } class Test { public static void Main() { Circle c = new Circle(); c.X = 35; } } In this code, the get or set accessor is called when the property X is referenced.
Vikas Amin EATON PUNE
-
when i declared a method string getName(){return this.name}; string getAddress(){return this.address;}... get appears like blue color its means c# word, then this methods get and set how can i use them or how its use i hope, i can explain good
Dios creo un equipo perfecto a los demas los lleno de extranjeros
But whatis better using get & set or using getName();??
Dios creo un equipo perfecto a los demas los lleno de extranjeros
-
But whatis better using get & set or using getName();??
Dios creo un equipo perfecto a los demas los lleno de extranjeros
You don't have to type () with properties :P
-
You don't have to type () with properties :P
:laugh::laugh::laugh::laugh::laugh::laugh: ok dont problem ;)
Dios creo un equipo perfecto a los demas los lleno de extranjeros