Change the method
GetConnection
to this.
Remove the variable declaration of SqlConnection inside the method.
public class myConnection
{
public SqlConnection con { get; private set; }
public void GetConnection()
{
string str = "Data Source=HEND-PC;Initial Catalog=f_library;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
con = new SqlConnection(str);
con.Open();
}
}