PDA

View Full Version : سوال: کارای این کد



taha007
دوشنبه 31 تیر 1392, 16:30 عصر
میخواستم بدونم این کد چکار میکند

String.IsNullOrWhiteSpace(strInput) ? string.Empty : strInput

taha007
دوشنبه 31 تیر 1392, 16:32 عصر
String.IsNullOrWhiteSpace(strInput) ? string.Empty : strInput

strinput یک string هست

veniz2008
دوشنبه 31 تیر 1392, 16:41 عصر
سلام.
این کد، میگه اگه strInput خالی بود (حتی space هم باشه باز هم خالی محسوب میکنه)، رشته خالی رو برگردون (string.Empty) در غیر اینصورت خود strInput رو برگردون.

string strInput = "test";
MessageBox.Show(string.IsNullOrWhiteSpace(strInput ) ? string.Empty : strInput);
در این مثال چون strInput خالی نیست پس مقدار test چاپ میشه.
موفق باشید.

taha007
دوشنبه 31 تیر 1392, 18:17 عصر
متوجه شدم .تشکر