C
C#16mo ago
slayer.5995

❔ why does the output return 0

using System; public class HelloWorld { public static void Main(string[] args) { Naming n = new Naming("someone", 9); Console.WriteLine(n.Name + " " + n.Age); } } public class Naming { public string Name; public int Age; public Naming (string name, int age) { name = Name; age = Age; } }
7 Replies
MODiX
MODiX16mo ago
Angius
REPL Result: Success
public class Naming
{
public string Name;
public int Age;

public Naming (string name, int age)
{
name = Name;
age = Age;
}
}

Naming n = new Naming("someone", 9);
Console.WriteLine(n.Name + " " + n.Age);
public class Naming
{
public string Name;
public int Age;

public Naming (string name, int age)
{
name = Name;
age = Age;
}
}

Naming n = new Naming("someone", 9);
Console.WriteLine(n.Name + " " + n.Age);
Console Output
0
0
Compile: 640.475ms | Execution: 81.193ms | React with ❌ to remove this embed.
Angius
Angius16mo ago
Huh Ah You're doing the assignment backwards Instead of setting Age to the value of age, you set age to the value of Age Which, by default, is 0
MODiX
MODiX16mo ago
Angius
REPL Result: Success
default(int)
default(int)
Result: int
0
0
Compile: 250.586ms | Execution: 23.895ms | React with ❌ to remove this embed.
slayer.5995
slayer.5995OP16mo ago
i see thanks that was dumb
Denis
Denis16mo ago
$close
MODiX
MODiX16mo ago
Use the /close command to mark a forum thread as answered
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?