c# - Concat list null check -
i have 5 variables in have individual data, after concatenating respective charge volumes 1 variable. works fine.
now issue suppose have 1 data (var ccpcv
has data) , rest not have data, var combinedpcv
line breaks because charge volume null other variables. there can n number of scenarios (2 have data, 3 have data etc).
one approach check each individual variable null value , null check on combination of variables.
please suggest better approach.
var ccpcv = (guidedpcvyear1ccviewmodel)wizard.steps[est bettgwizard.orderedsteps[typeof(guidedpcvyear1ccviewmodel)]]; var cpcpcv = (guidedpcvyear1cpcviewmodel)wizard.steps[wizard.orderedsteps[typeof(guidedpcvyear1cpcviewmodel)]]; var vpaypcv = (guidedpcvyear1vpaviewmodel)wizard.steps[wizard.orderedsteps[typeof(guidedpcvyear1vpaviewmodel)]]; var bippcv = (guidedpcvyear1bipviewmodel)wizard.steps[wizard.orderedsteps[typeof(guidedpcvyear1bipviewmodel)]]; var gnicsccpcv = (guidedpcvyear1ccgnicsviewmodel)wizard.steps[wizard.orderedsteps[typeof(guidedpcvyear1ccgnicsviewmodel)]]; var combinedcv = ccpcv.chargevolumes.convertall(cv=>cv).concat(cpcpcv.chargevolumes.convertall(x=>x).concat(vpaypcv.chargevolumes.convertall(z=>z).concat(bippcv.chargevolumes.convertall(a=>a).concat(gnicsccpcv.chargevolumes.convertall(s=>s))))); year1chargevolumes = combinedcv.tolist();
you write helper method so:
public static ienumerable<t> concattreatingnullsasempty<t>(params ienumerable<t>[] sequences) { return sequence in sequences sequence != null item in sequence select item; }
then use follows:
ienumerable<int> seq1 = enumerable.range(1, 5); ienumerable<int> seq2 = null; ienumerable<int> seq3 = enumerable.range(6, 5); ienumerable<int> seq4 = null; ienumerable<int> seq5 = enumerable.range(11, 5); var numbers = concattreatingnullsasempty(seq1, seq2, seq3, seq4, seq5); console.writeline(string.join(", ", numbers)); // prints 1, 2, ..., 14, 15
i think code this:
var combinedcv = concattreatingnullsasempty( ccpcv .chargevolumes, cpcpcv .chargevolumes, vpaypcv .chargevolumes, bippcv .chargevolumes, gnicsccpcv .chargevolumes);
Comments
Post a Comment