PDA

View Full Version : Authomatic Properties



Mostafa_Dindar
جمعه 25 دی 1388, 11:18 صبح
سلام .
من در مورد نحوه استفاده از Automatic Properties ها مشکل دارم . اگر چه دارم با VS 2008 کار میکنم ولی هنوز هم از روش قدیمی در دات نت 2.0 استفاده میکنم.

من نمیدونم به طور مثال اگه بخواهم همچین کدی رو با استفاده از Automatic Properties ها بنویسم چطور باید بنویسم :

private string _name = string.Empty;
private string _family = string.Empty;
//A field with default value
private DateTime _releaseDate = System.DateTime.Now;


//ReadOnly Property
public string Name
{
get {return _name; }
}

//enforce validation rules on setting
public string Family
{
get {return _family; }
set
{
if (value.Length < 3)
Thow new Exception("Family need at least 3 character long");
else
_family = value;
}
}

// A property from two other fields
public string FullName
{
get { return _name + " " + _family; }
}

مرسی

پ. ن :
در عنوان Automatic رو اشتباه نوشتم .

Mostafa_Dindar
جمعه 25 دی 1388, 12:31 عصر
مرسي از توجهتون .

جواب رو پيدا كردم . در حقيقت نميشود . در صورتي كه بخواهيد هر منطقي رو در Automatic Property ها انجام بدين بايد از روش قبلي استفاده كنيد .