Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Practicing Methods | Structs & Enumerators
C# Beyond Basics
course content

Зміст курсу

C# Beyond Basics

C# Beyond Basics

1. Additional Structures & File Handling
2. Structs & Enumerators
3. Introduction to Object-Oriented Programming (OOP)
4. OOP Essentials
5. OOP Principles

bookPracticing Methods

The code contains a struct called Cypher which basically represents a kind of Caesar cipher.

Read the code and fill in the blanks to make sure it works properly. The following is how the final program is supposed to be:

  1. setText method converts the passed text into encoded text and stores it into the field text. This method takes one stringargument calledtext`, and the method does not return any value;
  2. rawText returns the text field content. This method takes no arguments;
  3. decodedText decodes the text field content and returns the result. This method also doesn't take any arguments.
cs

index

copy
1234567891011121314151617181920212223242526272829303132333435363738394041424344
using System; struct Cypher { public string text; ___ { string encodedText = ""; foreach(char chr in text) encodedText += (char) (chr + 7); ___ = encodedText; } public string rawText() { ___ } ___ { string decodedText = ""; foreach (char chr in this.text) decodedText += (char)(chr - 7); ___ } } class ConsoleApp { static void Main(string[] args) { Cypher text1 = new Cypher(); text1.setText("This is an example sentence."); Console.WriteLine(text1.rawText()); Console.WriteLine(text1.decodedText()); } }

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 7
We're sorry to hear that something went wrong. What happened?
some-alt