Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Variable Declaration | Getting Started
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# Basics

bookChallenge: Variable Declaration

Complete the code by declaring the variables value_1 and value_2 having values 10 and 20 respectively.

Note
Note

You can combine strings and numbers in C# output using the + operator. When you use + between a string and a number, C# automatically converts the number to its string form and joins them together. For example, "Result: " + 5 will output Result: 5.

main.cs

main.cs

copy
12345678910111213141516
namespace ConsoleApp { internal class Program { static void Main(string[] args) { // Write code below this line // Write code above this line System.Console.WriteLine("Value 1: " + value_1); System.Console.WriteLine("Value 2: " + value_2); } } }
  1. Use the var keyword and the assignment operator (=) for variable declaration.
main.cs

main.cs

copy
1234567891011121314151617
namespace ConsoleApp { internal class Program { static void Main(string[] args) { // Write code below this line var value_1 = 10; var value_2 = 20; // Write code above this line System.Console.WriteLine("Value 1: " + value_1); System.Console.WriteLine("Value 2: " + value_2); } } }
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 9

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookChallenge: Variable Declaration

Swipe to show menu

Complete the code by declaring the variables value_1 and value_2 having values 10 and 20 respectively.

Note
Note

You can combine strings and numbers in C# output using the + operator. When you use + between a string and a number, C# automatically converts the number to its string form and joins them together. For example, "Result: " + 5 will output Result: 5.

main.cs

main.cs

copy
12345678910111213141516
namespace ConsoleApp { internal class Program { static void Main(string[] args) { // Write code below this line // Write code above this line System.Console.WriteLine("Value 1: " + value_1); System.Console.WriteLine("Value 2: " + value_2); } } }
  1. Use the var keyword and the assignment operator (=) for variable declaration.
main.cs

main.cs

copy
1234567891011121314151617
namespace ConsoleApp { internal class Program { static void Main(string[] args) { // Write code below this line var value_1 = 10; var value_2 = 20; // Write code above this line System.Console.WriteLine("Value 1: " + value_1); System.Console.WriteLine("Value 2: " + value_2); } } }
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 9
some-alt