خرید بک لینک

Vote count: 0

i have a scenario where a property is define as null able int and i have dictionary where the keys and values are loaded.i want to get the value by giving a key which is nullable int type and if key is null or key is not exist in dictionary then dictionary retu a default value.

this is an example

public partial class Form1 : Form
{
    Dictionary<int, string> students = new Dictionary<int, string>()
{
    { 111, "a"},
    { 112, "b"},
    { 113, "c"}
};
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int? a;
        a = 111; //this value is coming from somewhere else and it can be null
        string student = students[a];
    }


}

if we define int? a; as int a; then it is not giving error.but i have to make "a" variable as null able. please help me.

asked 25 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 24 تير 1395 ساعت: 12:39

صفحه بندی