Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Create and run simple C# console applications (Get started with C#, Part 2) Microsoft Quiz Answers

Get Create and run simple C# console applications (Get started with C#, Part 2) Microsoft Quiz Answers

Use Visual Studio Code to develop C# console applications that implement arrays, foreach loops, and if statements.

Get Started With C# All Parts:

Prerequisites:

  • Declare string, numeric, and Boolean variable types in C#.
  • Perform basic string and numeric operations in C#.
  • Write simply formatted string and numeric information to the console.

Enroll on Microsoft

Module 1: Install and configure Visual Studio Code

Learn how to configure Visual Studio Code for C# and how to use this professional IDE to create and run console applications.

Learning objectives:

In this module, you will:

  • Configure Visual Studio Code and your development environment for programming in C#.
  • Explore the Visual Studio Code user interface.
  • Create, edit, build, and run a console application using Visual Studio Code.

Learn how to configure Visual Studio Code for C# and how to use this professional IDE to create and run console applications.

Learning objectives:

In this module, you will:

  • Configure Visual Studio Code and your development environment for programming in C#.
  • Explore the Visual Studio Code user interface.
  • Create, edit, build, and run a console application using Visual Studio Code.

Quiz 1: Knowledge check

Q1. Which of the following choices provides the best description of an Integrated Development Environment (IDE)?

  • Visual Studio Code is an Integrated Development Environment.
  • An Integrated Development Environment is tool that makes it easier to write code.
  • An IDE is a suite of tools that supports the full software development lifecycle.

Q2. Which area of the Visual Studio Code user interface is used to write code?

  • Explorer.
  • Extensions.
  • Editor.

Q3. Which of the following tools is required to run command line interface commands such as dotnet run?

  • Visual Studio Code.
  • The OmniSharp extension for C#.
  • The .NET SDK.

Module 2: Call methods from the .NET Class Library using C#

Use functionality in the .NET Class Library by calling methods that return values, accept input parameters, and more.

Learning objectives:

In this module, you will:

  • Write code that calls stateless methods in the .NET Class Library.
  • Create a new instance of .NET Class Library classes to call methods that maintain state.
  • Use IntelliSense to learn more about a method, its overloaded versions, its return value data type, and its input parameter data types.
  • Use Microsoft Learn documentation to research what a method does, its overloaded versions, its return value type, its input parameters and what each parameter represents.

Prerequisites:

  • Experience declaring, initializing, and accessing the values of variables in C#.
  • Experience using the basic C# data types including int and string.
  • Experience using the method Console.WriteLine() in C#.

This module is part of these learning paths:

Quiz 1: Get started with .NET Libraries

Q1. How do you find information on the .NET classes and methods you are using?

  • .NET Class Library.
  • Developer websites.
  • .NET Class Library, Google search, and developer websites.

Quiz 2: Exercise – Call the methods of a .NET Class

Q1. Which of the following represents the correct way to create a class instance?

  • Random dice = new Random.Next();.
  • Random dice = new Random();.
  • String dice = new Random();.

Q2. A developer creates an instance of the Random class named coins. Which of the following code lines can they use to implement the Next() method?

  • int money = new coins.Next();.
  • int money = Random.Next();.
  • int money = coins.Next();.

Quiz 3: Exercise – Return values and input parameters of methods

Q1. What is a return value?

  • It’s a value type returned by a method.
  • An argument in a method call is referred to as a return value inside the method.
  • It’s a string value.

Q2. What are input parameters?

  • Value types (or variables) inside a method.
  • Values returned by a method.
  • The values passed into a method in the calling statement.

Q3. What is an overloaded method?

  • A method that returns a value type.
  • A method with more than five parameters.
  • It is a method that supports several implementations of the method, each with a unique method signature.

Q4. How does IntelliSense help developers?

  • IntelliSense can help developers write code more quickly.
  • IntelliSense helps developers refactor their code.
  • IntelliSense can change the “theme” of an IDE.

Quiz 4: Knowledge check

Q1. What is an object?

  • A memory address.
  • A stateless class.
  • An instance of a class.

Q2. Which of the following statements is true?

  • The .NET Class Library always defines overloaded methods for every method.
  • The .NET Class Library contains definitions for data types used in C#.
  • The .NET Class Library includes so many classes that it actually increases development time.

Q3. Which of the following symbols represent the method invocation operator required to execute a method?

  • .
  • {}
  • ()

Module 3: Add decision logic to your code using `if`, `else`, and `else if` statements in C#

Learn to branch your code’s execution path by evaluating Boolean expressions.

Learning objectives:

In this module, you will:

  • Write code that evaluates conditions using if, else, and else if statements.
  • Build Boolean expressions to evaluate a condition.
  • Combine Boolean expressions using logical operators.
  • Nest code blocks within other code blocks.

Prerequisites:

  • Experience declaring, initializing, setting, and retrieving variables by using the int data type.
  • Experience printing messages to output by using Console.WriteLine().
  • Experience with string interpolation to combine variables into literal strings.
  • Experience working with the System.Random class to generate random numbers.

This module is part of these learning paths:

Quiz 1: Exercise – Create decision logic with if statements

Q1. What is a code block?

  • A .NET Class Library.
  • Lines of code that should be treated as a single unit.
  • A block of code that is blocked from being accessed.

Q2. What is a Boolean statement or expression?

  • A modulus expression.
  • An ordinal term.
  • Code that returns either true or false.

Quiz 2: Knowledge check

Q1. Given that int x = 5, which of the following Boolean expressions is valid and evaluates to true?

  • x < 5.
  • x > 5.
  • x == 5.

Q2. Which of the choices below is not a valid operator in C#?

  • %%.
  • &&.
  • ||.

Q3. The following answer choices describe if statement syntax. Which of the descriptions is correct?

  • The Boolean expression evaluated by an if statement is optional.
  • An else statement can’t be placed before an else if statement.
  • The else statement is required when an if statement includes an else if.

Module 4: Store and iterate through sequences of data using Arrays and the foreach statement in C#

Work with sequences of related data in data structures known as arrays. Then, learn to iterate through each item in the sequence.

Learning objectives:

In this module, you will:

  • Create and initialize a new array.
  • Set and get values in arrays.
  • Iterate through each element of an array using the foreach statement.

Prerequisites:

  • Experience with declaring and initializing variables and basic data types like string.
  • Experience with printing to output using Console.WriteLine().
  • Experience with string interpolation to combine literal strings with variable data.
  • Experience researching how to use methods from the .NET Class Library.

This module is part of these learning paths:

Quiz 1: Exercise – Get started with array basics

Q1. What is an array?

  • A string variable.
  • A sequence of individual data elements accessible through a single variable name.
  • A .NET Class Library.

Q2. Which of these is a correct example of creating an array and initializing it?

  • string[] myarray = new string[3]; myarray = "test1"; myarray = "test2"; myarray = "test3";.
  • string[] myarray = string[3]; myarray[0] = test1; myarray[1] = test2; myarray[2] = test3;.
  • int[] myarray = new int[3]; myarray[0] = 1; myarray[1] = 2; myarray[2] = 3;.

Quiz 2: Knowledge check

Q1. Which of the following can be used to access the third element in an array?

  • myArray[3].
  • myArray[2].
  • myArray{3}.

Q2. Which of the following choices describes the correct way to create a new integer array with three elements?

  • int[] myArray = new int[3];.
  • int[] myArray = new int[2];.
  • int myArray = new int[3];.

Q3. Which of the following foreach statements is syntactically correct?

  • foreach (int value in values).
  • foreach (int value of values).
  • foreach (int value with values).

Module 5: Create readable code with conventions, whitespace, and comments in C#

Write code that is easier to read, update and support using naming conventions, comments and whitespace.

Learning objectives:

In this module, you will:

  • Choose descriptive names for variables that describe their purpose and intent.
  • Use code comments to temporarily instruct the compiler to ignore lines of code.
  • Use code comments to describe higher-level requirements or purpose for a passage of code.
  • Write code that effectively uses whitespace to convey the relationship of lines of code.

Prerequisites:

  • Experience declaring variables using common data types.
  • Experience using Console.WriteLine() to output messages to a console.
  • Experience using the if and else if statement.

This module is part of these learning paths:

Quiz 1: Choose variable names that follow rules and conventions

Q1. Which of the following is an example of correct camel case formatting of a variable name?

  • UserOption.
  • user Option.
  • userOption.

Quiz 2: Knowledge check

Q1. Which of the following demonstrates recommended guidelines for naming a variable?

  • my-string.
  • initialMessage$.
  • initialMessage.

Q2. Which of the following is a bad reason to use a code comment?

  • To describe the high-level intent of the code.
  • To explain how a new C# keyword works.
  • To temporarily comment out a line of code while evaluating a feature in a different way.

Q3. Which of the following statements about using whitespace in code is true?

  • Reducing the amount of whitespace will improve code performance (execution speed).
  • Whitespace should be used every two or three lines to separate code lines.
  • Whitespace should be used judiciously to improve the readability of your code.

Module 6: Guided project – Develop foreach and if-elseif-else structures to process array data in C#

Gain experience developing a console app that implements arrays, foreach loops, and if statements to achieve app specifications.

Learning objectives:

In this module, you’ll practice how to:

  • Use Visual Studio Code to develop a C# console application that uses foreach loops to access array data.
  • Use if statements to evaluate conditions and create code branches.

Prerequisites:

  • Experience using Visual Studio Code to develop, build, and run C# console applications that include console I/O and access the methods of .NET classes.
  • Experience using if statements in C# to evaluate an expression and branch code accordingly.
  • Experience using a foreach loop to access elements of array variables.

This module is part of these learning paths:

Quiz 1: Knowledge check

Q1. A developer writes an application that uses a foreach loop to iterate through an array containing 20 elements. After the application is complete, the developer learns that the array must be updated to include 40 elements. The application needs to examine all 40 array elements. Which of the following items describes the required code update?

  • Create a second foreach loop that iterates through the additional items.
  • No changes are required to the foreach loop.
  • Place the original foreach loop inside the code block of a second foreach loop that iterates twice.

Q2. A developer is working on a nested foreach structure that iterates through all of an application’s data arrays. The first array contains the names of locations where water samples were collected. The remaining arrays contain the test results for the samples collected from each named location. Which of the following statements about how the arrays should be processed is correct?

  • Each of the arrays containing samples can be processed by the outer loop, the inner loop will be used to verify the location.
  • The order in which the arrays are processed doesn’t matter since the application has to process all of the data.
  • The outer loop must process the array containing locations, the inner loop must process the arrays containing samples.

Module 7: Challenge project – Develop foreach and if-elseif-else structures to process array data in C#

Demonstrate your ability to update a console app that implements arrays, foreach loops, and if statements in response to a user requested feature update.

Learning objectives:

In this module, you’ll demonstrate your ability to:

  • Revise a C# console application that uses nested foreach loops to access array data based on an updated feature specification.
  • Update the variables and if statements in a C# console application to create the code branches and calculations required to satisfy an updated feature specification.

Prerequisites:

  • Experience using Visual Studio Code to develop, build, and run C# console applications that include console I/O and access the methods of .NET classes.
  • Experience using if statements in C# to evaluate an expression and branch code accordingly.
  • Experience using a foreach loop to access elements of array variables.

This module is part of these learning paths:

Quiz 1: Knowledge check

Q1. A developer is working on a nested foreach structure that iterates through the application’s array data. The first array contains the names of 10 geographic regions. The remaining arrays are based on the 10 regions. Each regional array contains the population of cities that have a population over one million. The population values in the regional arrays go from largest to smallest. The application sums the 25 most populated cities in each region. How should the developer ensure that only the 25 largest populations are added to the sum?

  • The developer should insert a “marker value” into the population arrays. The “marker value” should be added at index position 25. When the marker value is detected, the application should stop adding values to the sum.
  • The developer should check the index number of the current array element inside the foreach code block. The application should stop adding values to the sum when the index number reaches 25.
  • The developer should increment a counter inside the foreach code block. The application should stop adding values to the sum when the counter reaches 25.

Q2. A developer is working with two other developers to update a collection of applications. The developers will use code comments during the update process. Which of the following describes an appropriate use of code comments?

  • When updates are made, the developers use line and block comments to identify each individual code update.
  • When updates are made, the developers leave all existing code comments intact. New comments are added to indicate when old comments no longer apply.
  • When updates are made, the developers summarize changes using block comments.
Conclusion:

I hope this Create and run simple C# console applications (Get started with C#, Part 2) Microsoft Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>
Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *