Home > Net >  C # void incoming jobject parameters, can only assignment, to new jobject () is invalid, what reason
C # void incoming jobject parameters, can only assignment, to new jobject () is invalid, what reason

Time:01-26

HTML code is as follows, the incoming JObject job object, meet after three, automatic emptying job=new JObject (); Still have value, but the outside of the job, what reason be?
 public void addImgJarry (JArray jimg, JObject job, JToken rs, string imgName, int sort) 
{
If (BLL. JsonDo. GetJTokenKey (rs) IndexOf (imgName) & gt; 1)
{


String STR=the BLL. JsonDo. GetJTokenKey (rs). Replace ("/", "[");
STR=STR. Replace ("] ", "] ");
Sort=Common. Util. ConvertInt32 (BLL. BLLBase. GetsTr (STR, "[]", ""), 0).
String itemName=STR. Split (' [') [0];




If (itemName==imgName)
Job. The Add (imgName, the BLL. JsonDo. GetJTokenValue (rs));
If (itemName==imgName + "_t")
Job. The Add (imgName + "_t", the BLL. JsonDo. GetJTokenValue (rs));
If (itemName==imgName + "_s")
Job. The Add (imgName + "_s", the BLL. JsonDo. GetJTokenValue (rs));

If (job. Count==3)
{
Job. The Add (" sort ", sort);
Jimg. Add (job);
Job=new JObject ();
JObject TMP=the job;
}

}

}

CodePudding user response:

Function passed object argument, namely actually passed in is the object of reference, the address, that is to say, this argument points to the caller of the definition of the original object address, when you are on the job assignment in the function, after the job to a new address, but the caller of the original object is still pointing to the original address, so the original object won't change, if want to empty the contents of the job, not on the job assignment, should call the job of the Clear method (if any),

CodePudding user response:

reference 1st floor datafansbj response:
function passed objects, namely the argument, the actual passed is the object of reference, the address, that is to say, this argument points to the caller of the definition of the original object address, when you are on the job assignment in the function, after the job to a new address, but the caller of the original object is still pointing to the original address, so the original object won't change, if want to empty the contents of the job, not on the job assignment, should call the job of the Clear method (if any),


But the job is coming from the outside is changed, because can perform to the if (job. Count==3), the content of the inside I add a JObject TMP=the job; Is cleared, but outside of the job is not empty, added to the array Jimg, cycle to 4 times, job. The Add (imgName, the BLL. JsonDo. GetJTokenValue (rs)); The zhangs, unable to add this object, to make mistakes

CodePudding user response:

Ref know about the

CodePudding user response:

The
reference 3 floor hands on the keyboard to knock very light response:
ref know about the
thank you very much, is this thing!
  •  Tags:  
  • C#
  • Related