+ 1
How it works?
What will be the result? int n; n = (7 * 5 > 6 * 6) ? (7 * 9 > 8 * 8) ? 11 : 12 : (7 * 8 > 9 * 6) ? 13 : 14; Console.Write(n); (output 13)
4 Answers
+ 1
The ? : acts as a short version of if else statement so to write it out.
int n;
n = (7 * 5 > 6 * 6)
? (7 * 9 > 8 * 8) ? 11 : 12
: (7 * 8 > 9 * 6) ? 13 : 14;
Console.Write(n);
(output 13)
will equal to
int n;
if (7 * 5 > 6 * 6){
if(7 * 9 > 8 * 8){
n = 11;
}
else{
n = 12;
}
}
else if(7 * 8 > 9 * 6){
n = 13;
}
else{
n = 14;
}
Console.Write(n);
(output 13)
sence the first if statment is false it will skip the inside if statment and go to the else if that one is true so it makes n = 13.
hope this helps and isnt to confusing. also did this fast so sorry if there are any small errors in what i wrote out.
+ 1
this one is just because of the way it is adding the letters to make the word, if the letter in the function had â â then it is a char and will run the second function which is doing str(the word your making) = âuâ + str(currently ââ)
this will make str âuâ now.
second one uses â â which is a string so it will run in the first function which uses
str(currently âuâ) = str(âuâ) + ânâ
this makes str now âunâ
now the last one is a â â again so it runs on the second char function so the last time we add will be
str(currently âunâ) = âfâ + str(âunâ)
making str = âfunâ
so its all about how its being added you have to watch if its a char or string and which side your adding to.
0
#Mooaholic-great explanation,thanks,can you explain me another code
0
l hoped to see output-unf,but really output is fun,l am so confused
static string str = "";
static void Concat(string s) {
str= str + s;
Console.WriteLine("string");
}
static void Concat(char c) {
str = c + str;
Console.WriteLine("char");
}
static void Main() {
Concat('u');
Concat("n");
Concat('f');
Console.WriteLine(str);
}