Which big brother will tell me more about the use of Foreach?

Updated on Game 2024-05-07
6 answers
  1. Anonymous users2024-02-09

    foreach(child element type variable or object in array or collection) for example, this is a bit easier to understand.

    int num = ;

    foreach(int i in num);

    i is a child element of the array, and all types must be int. This will output the entire contents of the array.

    The syntax in foreach can be understood like this:

    A child element traverses through an array or collection.

  2. Anonymous users2024-02-08

    And when you use some collection-type loops such as arraylist.

    It is not possible to use a for loop.

    The only way to do this is to use Feacher.

  3. Anonymous users2024-02-07

    I'll add a little bit of the basics:

    1. The collection type is often used to traverse to foreach. For example, all the data in an array, or all the elements in the objects in the web, these objects can be traversed one by one using foreach.

    2. Since the collection can also be accessed according to the index, on the premise of knowing the length of the collection, the things implemented by foreach can be implemented with for and i++ in most cases, but the efficiency will be lower;

    3. Whether an object can use foreach, the most critical point is to implement the IENUMERATOR interface, or be declared as a type of getenumerator() method. (for C).

    Hopefully, the above three points can give you some help.

  4. Anonymous users2024-02-06

    The foreach loop is used to enumerate all the elements in the set, and the expression in the foreach statement consists of two items separated by the keyword in. The item to the right of in is the name of the collection, and the slippery item to the left of in is the variable name, which is used to store each element in the collection.

    Properties of the array: The capacity of the array

    Using this property, we can obtain the capacity value that the array object is allowed to store, that is, the length of the array, the number of elements, this is easier to understand, the array has other properties, such as the dimension of the array, etc., the use of the attribute is relatively simple, learn one, and the other formats are basically the same.

    Traversal array: foreach(type objname in collection array).

    This statement will check the values of the variables stored in the array one by one, and take them out one by one, where type is the data type of the array object you want to read will be stored in the objname variable, and objname is the variable name that defines a type type, representing each element obtained from the collection and array (collection array), and the collection array is the array object to be accessed. In this way, just write a foreach to iterate over an array of dimensions of all dimensions except interleaved arrays.

  5. Anonymous users2024-02-05

    foreach(child element type variable or object in array to bury or set) for example, so it's easier to understand.

    int num =

    foreach(int i in num);

    i is a child element of the array, and all types must be int. This will output the entire contents of the array.

    The method of slang in foreach can be understood in this way:

    A child nucleus differentiale traverses in an array or set.

  6. Anonymous users2024-02-04

    foreach usage: foreach (type identifier in expression) statement.

    Where: type: the type of identifier.

    identifier: Indicates the iterative change or laughter of the collection element. If the iteration variable is of value type, read-only variables that can't be modified are also valid.

    expression: A collection of objects or an array expression. The type of the collection element must be convertible to the identifier type. Please do not use expressions that evaluate to null.

    Instead, it should be evaluated as a type that implements an IENUMERABLE or declares a type of a getenumerator method. In the latter case, the getenumerator should return a type that implements the ienumerator or declares all the methods defined in the ienumerator.

Related questions
10 answers2024-05-07

360root is ok. I used the root I got with Phone Manager, and it works well.

6 answers2024-05-07

Now, the field of computer software has been divided into very fine. >>>More

10 answers2024-05-07

You know I'm okay.

There are some things you want to say. >>>More

9 answers2024-05-07

Since I don't know what way you want to make this description template, I can only list the existing 3 ways for you,,I've had this type of problem before.,Hee-hee, please forgive me for copy-pasting: >>>More

5 answers2024-05-07

You can't do this problem.

Judging by the question you asked, it seems that you don't know much about the system. >>>More