This job is a little weird. If you are practicing then it would be interesting to practice what is most important and at the same time easier because it is not even programming itself. If you make a mistake that’s how you always do it.
The function name is not good because it doesn’t say what it really does. Unless she does something that is not yet in the code, but in this case a comment would be good, comments serve precisely for this.
The same goes for the return, if it will return something that is fixed, then it is better to return nothing, unless you will do other things later, and again a comment would be fine.
It makes no sense to use //
in the text, or uses \\
or uses /
. To \\
is necessary because the bar alone is an escape character since the backslash is used for formatting. Using the backslash can use the @
so you don’t have to duplicate it.
Can use interpolation there and avoid further headaches.
The mistake is that it is creating a tuple (example, another, one more, the last) composed of an object string
and other object string
with a name. And declared a variable of type string
only (which is obviously not a tuple, is incompatible).
The statement is correct, the assignment is wrong. The parentheses left there make all the difference by creating a different kind, so I always talk:
Even the space in the function name is unnecessary, does not give an error, but gives a wrong indication, it looks like you are grouping expressions or creating a tuple instead of using a function. It sounds silly but the code is less readable. Even if it works not everything is right, get used to doing right and not just working. The worst mistakes are the ones the compiler doesn’t complain about.
And the variable isn’t even necessary.
Would be better off:
static void PrepararTerreno() => Directory.CreateDirectory($"C:/Users/{Environment.UserName}/Documents/Cadastro");
Or
static void PrepararTerreno() => Directory.CreateDirectory($@"C:\Users\{Environment.UserName}\Documents\Cadastro");
Or else
static void PrepararTerreno() => Directory.CreateDirectory($"C:\\Users\\{Environment.UserName}\\Documents\\Cadastro");
I put in the Github for future reference.
String.Format("C://Users//{0}//Documents//Cadastro",Environment.UserName);
– Augusto Vasques
Thanks man this was giving me a headache
– Leonardo Lopes
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site
– Maniero