Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Basic Coding Practice | Dealing with Data Types
C# Basics

Basic Coding PracticeBasic Coding Practice

A number is stored in a variable called num in the form of a string. Add 2 to the stored number. You may use the following steps:

  • Convert the value of num string to an integer and store it in a new integer variable called temp.
  • Add 2 to the value of temp.
  • Convert the value of temp to a string and assign it to the variable num
cs

main.cs

1. Use Convert.ToInt32() and Convert.ToString().

using System;

namespace ConsoleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string num = "15";

            // Write code below this line
            int temp = Convert.ToInt32(num);
            temp = temp + 2;
            num = Convert.ToString(temp);
            // Write code above this line

            Console.WriteLine(num); // Expected Output: 17
        }
    }
}
      

Все було зрозуміло?

Секція 2. Розділ 14
course content

Зміст курсу

C# Basics

Basic Coding PracticeBasic Coding Practice

A number is stored in a variable called num in the form of a string. Add 2 to the stored number. You may use the following steps:

  • Convert the value of num string to an integer and store it in a new integer variable called temp.
  • Add 2 to the value of temp.
  • Convert the value of temp to a string and assign it to the variable num
cs

main.cs

1. Use Convert.ToInt32() and Convert.ToString().

using System;

namespace ConsoleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string num = "15";

            // Write code below this line
            int temp = Convert.ToInt32(num);
            temp = temp + 2;
            num = Convert.ToString(temp);
            // Write code above this line

            Console.WriteLine(num); // Expected Output: 17
        }
    }
}
      

Все було зрозуміло?

Секція 2. Розділ 14
some-alt