I am using below code to convert a string value to integer and set in nullable integer variable only if value is greater then zeor '0'.
NOTE: its working fine but i want experts advice to optimize it and make it a library function.
if (txtdownload.Text.Trim() != "") { int i = 0; int.TryParse(txtdownload.Text, out i); if (i > 0) { pad.Noofdownload = i;//Noofdownload is a property on nullable integer } } Please help to create a Optimized library function (common function), which i can use for all such a conversion.
Thanks a lot.
NOTE: i have created below library function but its not working for properties as we can't pass properties as a ref.
public static void getValueFromTextBoxInNullable(string srctext,ref int? dest) { if (srctext.Trim() != "") { int j = 0; int.TryParse(srctext , out j); if (j > 0) { dest = j; } } }