I have a class with many public accessor , one of which is the
list & Lt; String & gt; down it; My question is, this is:
In the code that gives the principle of this class, I am piping through a string in which many lines can be pi, so for each line of PI It's the
list & lt; String & gt; Want to add in P
So I have tried to:
instancenam.p.AddRange (string.Split (new four [] {':', ': '}) [2]); which gives me the value of the second set in a string such as : 23A: TETCGR
When I run the code, Follow:
Error 1:
The best overloaded method for System.Collections.Generic.List.AddRange Matching (System.Collections.Generic.IEnumerable) has some invalid argument
Error 2:
Argument 1: Can not convert 'string' from 'system.clalls. GENERIC. INNAMERABLE '* *
I have scored but are confused with the reactions; -)
Forresh (in string strings) {// it needs to be seen that the length is greater than 3. If (str! = "4:" & amp; str! = "") {// tag name
if (str.StartsWith (":") {tag = str. Split (new four [] {':', ':'}) [1]; SavedTag = tag; Switch (message type) {// tag 13c time signal if (tag == "13c") {mt202.tag13C.Add (str.Split (new four [] {':', ':'}) [2] ); } break; } OK, so due to being nominated, I now have the following:
Edit:
Public category MT202 {public string tag20 {get; Set; } Public string tag21 {get; Set; } Public listing & lt; String & gt; Tag 13C {Get; Set; } Public string tag 32A {get; Set; } Public string tag 33B {get; Set; }} // below call calling class if (tag == "13c") {char [] delimiters = new char [] {':', ':'}; String [] splitValues = str.Split (delimiter); String Single Value = Split Value [2]; & Lt; String & gt; Mt202.tag13C = New list & lt; String & gt; (); Mt202.tag13C.Add (singleValue); // mt202.tag13C.Add (str.Split (new four [] {':', ':'}) [2]);
Let's break this line:
Instancenam.p.AddRange (string.Split (new four [] {':', ':'}) [2]); I think the string part is actually the name of a variable ( string is not a valid identifier). I'll call text below.
The expanded code looks like this:
char [] delimiters = new char [] {':', ':'}; String [] splitValues = text.Split (delimiter); String Single Value = Split Value [2]; & Lt; String & gt; List = instancenam.pee; List.AddRange (singleValue); This will give the same error, because you are calling AddRange , which is to assume the values archive - but You are only providing a single price if you want to add only one value, then add :
instancenam.p. Add (text. Split (new four [] {':', ':'}) [2]); I recommend breaking the code that something like bit above the code given above - it is possible that it does not break down, but at least . (You can make a readable stable field for the delimiter to get started.)
Additionally, I can change the name of your property to something more meaningful than p PascalCase recommends for .net naming conventions.
EDIT: Now the post has been edited with:
I use the above mentioned object to render an instance of an object
It suggests that either mt202 or mt202.tag13C is a null reference, but we can not tell you Should look with the debugger.
No comments:
Post a Comment