exp is an array of elements of type object . how to access a specific object if it is not known in advance which and how many objects in the array
XmlSerializer xs = new XmlSerializer(typeof(export)); exp = (export)xs.Deserialize(stream); exp is an array of elements of type object . how to access a specific object if it is not known in advance which and how many objects in the array
XmlSerializer xs = new XmlSerializer(typeof(export)); exp = (export)xs.Deserialize(stream); Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
Arrays in C # are a sequence of several variables of the same type.
Array types are reference types derived from the abstract base type Array. Since this type implements IEnumerable and IEnumerable, in C #, you can use foreach iteration in all arrays.
The foreach operator repeats a group of nested statements for each element of an array or collection of objects that implement the System.Collections.IEnumerable or System.Collections.Generic.IEnumerable interface.
You deserialize an XML document using the XmlSerializer.Deserialize object. In the line of code:
exp = (export)xs.Deserialize(stream); // чтобы это был массив, нужно написать так: new XmlSerializer(typeof(export[])); // где export - это тип exp = (export[])xs.Deserialize(stream); You get an array of elements of a given type (with successful de-serialization). This array is amenable to the rules of working with arrays in C #. To find out the number of elements in an array, you can use the Array.Length ( exp.Length ) property — get the total number of elements in all dimensions of the Array array.
Thus, you can refer to any element of your array.
1. Enumerate all elements of your array using foreach :
foreach (var element in exp) { //... } 2. Refer to the index to the element in the for loop:
for (int index = 0; index < exp.Length; index++) { // var element = exp[index]; } 3. Refer to the index, observing the condition:
int index = 2; if(index < exp.Length) var element = exp[index]; Source: https://ru.stackoverflow.com/questions/556583/
All Articles
exportclass? exp - array of elements of type object - no,expis an object of classexport- Grundy