List
- Last UpdatedMar 12, 2025
- 2 minute read
This topic is about the List data type.
Value syntax
List<T> l = { a,b,c,d }
Syntax notes
Previous assignment syntax can be used only during initialization. The following code will raise an error.
List<T> l;
l = { a,b,c,d };
After an empty List is declared, it can be populated either by using the implemented API listed below or by assigning it the values from another List.
List<T> l;
List<T> l2 = { a,b,c,d };
l = l2;
Description
List type represents a strongly-typed list of objects that can be accessed by index.
-
The default value is an empty list of the specified type.
-
The List type partially supports Comparison operators.
-
In addition, it supports Indexer operator [].
ToMString examples
The ToMString command converts the list to a string of comma-separated values, which allows you to assign an XRS List to a XML mstring, as shown in the following code examples.
Code example in XML script
<Var name="mymstring" value=""/>
Code example in XRS script
List<string> list = {"a","b","c","d"};
Runtime::Scene.SetFieldValue("mymstring.value", list.ToMString());
Properties
|
Property |
Return type |
Parameters |
Description |
|---|---|---|---|
|
Count |
int |
|
Used to obtain the length of the list. |
Methods
|
Method |
Return type |
Parameters |
Description |
|---|---|---|---|
|
Add |
|
T value |
Adds an object value to the end of the List<T>. |
|
AddIfUnique |
T value |
Adds an object value to the end of the List<T>, if the List<T> does not already contains the value. |
|
|
AddRange |
List<T> |
Adds the element of the specified List at the end of List<T>. |
|
|
Clear |
|
|
Removes all elements from the list. |
|
Clone |
List<T> |
Returns a cloned copy of the list. If the list contains reference type entries, these are not copied, but referenced in the returned list. |
|
|
Contains |
bool |
T value |
Returns true if the list contains the given value, including character case. |
|
Distinct |
List<T> |
Returns a list of distinct elements from the source List<T> |
|
|
IndexOf |
int |
T value |
Returns the zero-based index of the first occurrence of value in the List<T> |
|
Insert |
|
int itemIndex T value |
Inserts value into the List<T> at the specified itemIndex. |
|
LastIndexOf |
|
T value |
Returns the zero-based index of the last occurrence of value in the List<T>. |
|
Remove |
bool |
T value |
Removes the first occurrence of a specific value from the List<T>. It returns true if the object is successfully removed and false if value is not found in the List<T>. |
|
RemoveAt |
|
int index |
Removes the element at specified index from the List<T>. |
|
Reverse |
|
|
Reverses the order of the elements in the List<T>. |
|
Sort |
|
|
Sorts the elements in the entire List<T> using the default comparer. |
|
ToMString |
string |
Converts the list to a string of comma separated values, allowing you to assign an XRS List to a XML mstring. See the ToMString examples in this topic. |