本文介绍了如何将var类型声明为全局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想使用var类型的声明作为全局,我这样使用,但它不接受,我怎么能全局声明这种类型的变量。或者我们有另外的声明来存储linq查询结果。只需 var testdata; int count; //计数值通过方法参数传递为1或2或3,在这里我宣布为样本 if(count == 1) { testdata =(来自s中的spe。联系人选择s)。orderbyDesending(x => x.id).take(1); } else if (count == 2 ) { testdata =(来自 s spe.contacts 选择 s)。orderbyDesending(x => x.id).take( 2 ); } if (count == 3 ) { testdata =(来自 s spe.contacts 选择 s)。orderbyDesending(x => x.id).take( 3 ); } 但它不接受,请帮我解决这个问题。解决方案 hi, i want to use var type of declarations as globally, i used like this, but it is not accepting, how can i declare this type of variable globally. or do we have another declarations to store linq query result. simplyvar testdata;int count;//count value is coming through method parameters as 1 or 2 or 3, here i have declared as sampleif(count==1){testdata=(from s in spe.contacts select s).orderbyDesending(x=>x.id).take(1);}else if(count==2){testdata=(from s in spe.contacts select s).orderbyDesending(x=>x.id).take(2);}if(count==3){testdata=(from s in spe.contacts select s).orderbyDesending(x=>x.id).take(3);}but it is not accepting, please help me to solve this. 解决方案 这篇关于如何将var类型声明为全局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!