c# - Cannot assign <null> to an implicitly-typed local variable -


i want to select field data table dt_branches_global in such way that, if radiobutton_qp checked data table contain string field otherwise data table contain int field. doing. getting error while initializing variable var.

var allbranch_ids = null;  if (radiobutton_qp.checked == true)    allbranch_ids = dt_branches_global.asenumerable().select(x => x.field<string>("businesssectorid")).toarray(); else  allbranch_ids = dt_branches_global.asenumerable().select(x => x.field<int>("businesssectorid")).toarray(); 

the compiler still typed needs figure out type. impossible compiler infer type of assign null. later on try assign 2 different types. array of ints , array of strings.

try like:

string[] allbranch_ids = null;  if (radiobutton_qp.checked == true)    allbranch_ids = dt_branches_global.asenumerable().select(x => x.field<string>("businesssectorid")).toarray(); else  allbranch_ids = dt_branches_global.asenumerable().select(x => x.field<int>("businesssectorid").tostring()).toarray(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -