当前位置: 首页 > 编程语言 > C#

Thename'str'doesnotexistinthecurrentcontext分享

时间:2023-04-11 01:45:43 C#

Thename'str'doesnotexistinthecurrentcontext我这里声明了一个类变量voiddownloader_OpenReadCompleted(objectsender,OpenReadCompletedEventArgse){if(e.Error==null){StreamresponseStream=e.Result;StreamReaderresponseReader=newStreamReader(responseStream);字符串响应=responseReader.ReadToEnd();string[]split1=Regex.Split(response,"},{");pri1=新列表(split1);pri1.RemoveAt(0);字符串last=pri1[pri1.Count()-1];pri1.删除(最后);我想在这个方法中使用classvariablestrvoidAddPrimaryMarkerGraphics(objectsender,getPrimaryListCompletedEventArgse){ListprimaryList=newList(e.Result);PrimaryClasssc=newPrimaryClass();for(inta=0;a<=e.Result.Count-1;a++){字符串schname=e.Result.ElementAt(a).PrimarySchool;字符串tophonour=e.Result.ElementAt(a).TopHonour;字符串cca=e.Result.ElementAt(a).Cca;stringtopstudent=e.Result.ElementAt(a).TopStudent;字符串topaggregate=e.Result.ElementAt(a).TopAggregate;stringtopimage=e.Result.ElementAt(a).TopImage;foreach(stringiteminstr){stringabc="[{"+item+"}]";byte[]buf=System.Text.Encoding.UTF8.GetBytes(abc);MemoryStreamms=newMemoryStream(buf);JsonArray用户=(JsonArray)JsonArray.Load(ms);varmembers=frommemberinusers//wheremember["SEARCHVAL"]selectmember;foreach(成员中的JsonObject成员){stringschname=member["SEARCHVAL"];字符串axisX=成员["X"];字符串axisY=成员["Y"];//做点什么...stringjsonCoordinateString="{'坐标':[{'X':"+axisX+",'Y':"+axisY+"}]}";CustomCoordinateList坐标列表=DeserializeJson(jsonCoordinateString);GraphicsLayergraphicsLayer=MyMap.Layers["MyGraphicsLayer_Primary"]asGraphicsLayer;对于(inti=0;i0?PrimarySchoolMarkerSymbol:PrimarySchoolMarker符号};graphic.Attributes.Add("小学",schname);graphic.Attributes.Add("xcoord",axisX);graphic.Attributes.Add("ycoord",axisY);graphicsLayer.Graphics.Add(图形);}}}}}显示错误的地方,有什么帮助吗?您几乎可以肯定是在方法中声明变量(即作为局部变量),而不是直接在类本身(作为实例变量)中声明变量,例如://WrongclassBad{voidMethod1(){Liststr=newList();}voidMethod2(){foreach(stringiteminstr){...}}}//RightclassGood{privateListstr=newList();voidMethod1(){str=CreateSomeOtherList();}voidMethod2(){foreach(stringiteminstr){...}}}作为旁注:如果您是C#的新手,我强烈建议您暂时停止使用Silverlight并编写一些控制台应用程序来帮助您去,教你基础知识。这样,您就可以在开始编写GUI之前将C#用作一种语言和核心框架类型(例如文本、数字、集合、I/O)。GUI编程通常涉及学习更多的东西(线程、XAML、绑定等),而尝试一次性学习所有内容只会让事情变得更难。它不起作用,因为str没有在另一个变量中声明。这是个问题。您可以将str作为输入传递给另一个函数吗?以上就是C#学习教程:名称'str'在当前上下文中不存在分享全部内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除。如需转载请注明出处: