What is the correct syntax for foreach statement in C#?

43. What is the correct syntax for foreach statement in C#?

  1. foreach(type variable_name in collection_name); {
      statement(s);
    }
    
  2. foreach(type variable_name in collection_name) {
      statement(s);
    }
    
  3. foreach(variable_name As Type in collection_name){
      statement(s);
    }
    
  4. foreach(dim type variable_name in collection_name) {
      statement(s);
    }
    

Answer: B)

foreach(type variable_name in collection_name) {
  statement(s);
}

Explanation:

The correct syntax of foreach statement is:

foreach(type variable_name in collection_name) {
  statement(s);
}

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.