selectedItem
has two fields:
int? _cost
string _serialNumber
In this example, _cost
A string is a reference type, but a nullable int is a value type. Here is a Good discussion of the differences http://www.albahari.com/valuevsreftypes.aspx.
TextBox2.Text = selectedItem.SerialNumber.ToString(); //error
yiels error because it's calling function ToString() which is member of System.String. This function returns this instance of System.String; no actual conversion is performed. Also, String is a reference type. A reference type contains a pointer to another memory location that holds the data.
TextBox1.Text = selectedItem.Cost.ToString(); //no error
yields no error because it's calling to function ToString() which is a member of System.Integer. This function converts the numeric value of this instance to its equivalent string representation. Also, Integer is a value type. A data type is a value type if it holds the data within its own memory allocation.
The same function name ToString() but performs different task.
String.ToString Method
Int32.ToString Method
Value types and reference types