This guide will walk you through filling in the question marks with variables in the provided code. By following the instructions below, you will learn how to use variables and various string methods in C#.
- Uncomment the following line of code:
// Console.WriteLine(?); // simple print using console - Replace the question mark with a string variable of your choice.
- Run the program to see the output.
- Uncomment the following line of code:
// Console.WriteLine(?); // finds the number of characters in a string using .Length - Replace the question mark with a string variable of your choice.
- Run the program to see the output.
- Uncomment the following line of code:
// Console.WriteLine(?); // string interpolation e.g Console.WriteLine($"The name Azhar has {myname.Length} characters"); // string interpolation - Replace the question mark with a string variable of your choice.
- Run the program to see the output.
- Uncomment the following line of code:
// string newName = yourname.Trim(); // you can trim the spaces of a string using .Trim() method e.g Console.WriteLine(yourname.Trim()); // you can also print out your new trim as a variable newName - Replace the question marks with a string variable and a new variable name of your choice.
- Run the program to see the output.
- Uncomment the following line of code:
// string ? = ?.ToUpper(); // use .ToUpper() to change a string to uppercase - Replace the question marks with a string variable of your choice.
- Run the program to see the output.
- Uncomment the following line of code:
// string newSentencepractice = sentencepractice.Replace("?", "?"); // try out the replace method and see what it does - Replace the question marks with a string variable and a new variable name of your choice.
- Run the program to see the output.
- Uncomment the following line of code:
// Console.WriteLine(?.Length); // more practice with string methods - Replace the question mark with a string variable of your choice.
- Run the program to see the output.
- Uncomment the following line of code:
// Console.WriteLine(?.Replace("?", "?")); // Console.WriteLine(?.ToUpper());
- Replace the question marks with a new string variable and a value of your choice.
- Run the program to see the output.
- Uncomment the following lines of code:
// Sample program utilizing all the concepts. // Console.WriteLine("Azhar "); // simple print // string myName = "Azhar"; // Console.Write($"My name is {myName.TrimEnd()} and it has {myName.Length} characters. Jokes it is Actually 5 Characters."); // Console.WriteLine($" It can also be written in uppercase like this {myname.Trim().ToUpper()} and now I will share a bit about my history"); // string history = $"As I said my name is {myname.Trim()} and it is made up of {myname.Length} letters. {newSentencepractice.Replace("My name is", "My job description is")}"; // Console.WriteLine(history);
- Replace the question marks with appropriate string variables and values of your choice.
- Run the program to see the output.
- Uncomment the following lines of code:
// Remove the "/*" and "*/" to activate the program below /* if(?.StartsWith("a") == true) { // we will use this program to test out the StartsWith method Console.WriteLine("yey"); } else if (myName.StartsWith("Ahar") == true) { Console.Write("I would have never known"); } else { Console.WriteLine(false); } var ? = ?.ToCharArray(); Console.WriteLine(?.Reverse()); if (?.EndsWith("R") == true) { Console.Write("hmm, are you a genius"); } else if (?.EndsWith("ar") == false) { Console.WriteLine("ha, got em"); } else { Console.WriteLine("I think soon we will get the hang of this if we keep experimenting"); }
- Replace the question marks with appropriate string variables and values of your choice.
- Run the program to see the output.
Congratulations! You have successfully filled in the question marks with variables based on the provided code. Keep experimenting and exploring different concepts to enhance your programming skills.