Explanation about the coding in the example.

Posted by Gokul under C# on 5/31/2011 | Points: 10 | Views : 1165 | Status : [Member] | Replies : 3
Dear Friends,
I have downloaded the sample project of slideshow from one of the project. The Project is working well. But i cant understand the coding that is involved in it. I want to know what is the use of each term in it. Can any help me in solving out.



public class ImageItem
{
private string _ToolTip = string.Empty;
public string ToolTip
{
get { return _ToolTip; }
set { _ToolTip = value; }
}

private string _URL = string.Empty;
public string URL
{
get { return _URL; }
set { _URL = value; }
}

// Default constructor.
public ImageItem()
{ }

public ImageItem(string ToolTip, string URL)
{
this._ToolTip = ToolTip;
this._URL = URL;
}
}

public class ImageItems : List<ImageItem>
{
public ImageItems()
{ }
}

public class SlideShowImageEventArgs : EventArgs
{
private ImageButton _ImageButton = null;
private int _X = 0;
private int _Y = 0;

public int X
{
get { return _X; }
}

public int Y
{
get { return _Y; }
}

public string URL
{
get { return _ImageButton.ImageUrl; }
}

public string ToolTip
{
get { return _ImageButton.ToolTip; }
}

public SlideShowImageEventArgs(ImageButton O, int X, int Y)
{
_ImageButton = O;
_X = X;
_Y = Y;
}
}

//Delegate that represents the Click event signature for SlideShow control.
public delegate void SlideShowClick(object sender, SlideShowImageEventArgs e);


--------------------------------------------------------------------------------------------------------------------------
-----------------------------End of the Coding ------------------------------------------------------------------



In this coding they have used get and set methods. What is the use of it? Why we are using it?
EG:

private string _Title = string.Empty;
public string Title
{
get { return _Title; }
set { _Title = value; }
}


private HorizontalAlign _ArrowAlign = HorizontalAlign.NotSet;
public HorizontalAlign ArrowAlign
{
get { return _ArrowAlign; }
set { _ArrowAlign = value; }
}

Thanks and Regards,
GokulNath Nithy.



Responses

Posted by: Ndebata on: 5/31/2011 [Member] Starter | Points: 25

Up
0
Down
This how we used to define properties of a class.
But from c#3.0 onwards you directly write.
public string Title {get;set;}
instead of
private string _Title = string.Empty; 

public string Title
{
get { return _Title; }
set { _Title = value; }
}

To know more about property please refer this link
http://msdn.microsoft.com/en-us/library/aa288470(v=vs.71).aspx



Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/31/2011 [Member] Bronze | Points: 25
Posted by: Susanthampy on: 5/31/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Refer this link,

http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx

Regards,
Susan

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response