0
Introduction to C# â> Methods â> Whitespace
The gaps appeared in front of me like an insurmountable wall... static string Concat(string x, string y) { string res = ***; return res; } string msg = Concat("Finishing ", "the last module"); Console.WriteLine(message); I understand perfectly well what should be written here, but how exactly is it written in the system? "x+y" or still "x + y"? By the way, there is also an error in the code... the variable is "msg", and the variable "message" is output to the console. I'm afraid to check, I'll lose my heart... instead, I'm going to "C# intermediate level")))
9 Respostas
+ 1
idk. I was not able to input x + y...
maybe it is device dependent? I am on Android phone using Sololeran app.
+ 2
Wow.
Unexpected difference.
Thanks, I entered "x+y", the answer was counted)
It seems, however, that the difference is in the device.
I'm using my computer's browser.
Hah, everything is as I thought.
In the comments they complain about "x + y" not counted)))
+ 1
Animaliss
using Concat
string result = String.Concat(first, second);
or normal Concatenate method
using System;
namespace MyNamespace // Optional namespace
{
class Program
{
static void Main(string[] args)
{
string first = "Sololearn ";
string second = "is fun";
string msg = first + second; // Concatenate using + operator
Console.WriteLine(msg);
}
}
}
https://sololearn.com/compiler-playground/c121gcoygU51/?ref=app
+ 1
use
x+y
the input box doesn't even allow x + y. it is limited to 4 characters.
This interestingly reveals a weakness in the test. x + y should be allowed and also be considered as a correct answer. But it is what it is and you can only use x+y...
0
Extra whitespace is generally ignored in C#.
x+y and x + y are identical.
Whitespace is important as separators between type declaration and variable name, though.
int x and intx are obviously different.
Maybe you mean formatting? These are implemented for code standardization and readability preferences.
0
Hey, I know that in C# extra spaces are ignored)
But they are not ignored in sololearn tasks.
There, the string in the database and the string you enter are checked to see if they match.
0
oh, you mean spaces in strings? Then yes, they are important.
"x+y" != "x + y"
"sololearn" != " sololearn"
and Sololern's input box also includes the extra whitespaces you type in. Being careful in typing is super important.
0
It seems you didn't understand the idea/request.
Sololearn has tasks of this format:
*Fill in the blanks to get a method that returns a string concatenation*
static ___ Concat(string x, string y)
{
string res = ___;
___ res;
}
string msg = ___("Finishing ", "the last module");
Console.WriteLine(msg);
The database contains an array of the following type:
string[] rightAnswers = { "string", "x+y", "return", "Concat" };
Then the user enters their answers:
string[] userAnswers = { "string", "x + y", "return", "Concat" };
And finally, the system checks:
for (int i = 0; i < rightAnswers.Length; i++)
if (rightAnswers[i] != userAnswers[i])
Console.WriteLine("The answer is incorrect, you have a minus heart");
// Will work on userAnswers[1]
else
Console.WriteLine("Everything is correct, you can move on to the next task");
And I want to know what answer is contained in the variable rightAnswers[1], with spaces or not?
I know the right answer, but I don't know which one is in the database, so I'm afraid of losing a heart, and they take 4.5 hours to restore.
Maybe someone has recently completed it or has unlimited hearts and can check it.
It's in the "Module 5 Test Questions" section, the very last item on "C# for Beginners".
0
It is limited to 5 characters)
By the way, the field where I have to enter string is limited to 7 characters.
(And the other 2 fields are limited to 9 characters)
In general, the number of possible characters does not match the length of the accepted word.