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

Kursinnhold

C# Basics

C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

book
Basic 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:

  1. Convert the value of num string to an integer and store it in a new integer variable called temp.

  2. Add 2 to the value of temp.

  3. Convert the value of temp to a string and assign it to the variable num

cs

main

copy
123456789101112131415161718
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string num = "15"; // Write code below this line // Write code above this line Console.WriteLine(num); // Expected Output: 17 } } }

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

cs

main

copy
1234567891011121314151617181920
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 } } }

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 14

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

course content

Kursinnhold

C# Basics

C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

book
Basic 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:

  1. Convert the value of num string to an integer and store it in a new integer variable called temp.

  2. Add 2 to the value of temp.

  3. Convert the value of temp to a string and assign it to the variable num

cs

main

copy
123456789101112131415161718
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string num = "15"; // Write code below this line // Write code above this line Console.WriteLine(num); // Expected Output: 17 } } }

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

cs

main

copy
1234567891011121314151617181920
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 } } }

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 14
Vi beklager at noe gikk galt. Hva skjedde?
some-alt