C
C#15mo 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
MODiX15mo 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
Angius15mo 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
MODiX15mo 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.5995OP15mo ago
i see thanks that was dumb
Denis
Denis15mo ago
$close
MODiX
MODiX15mo ago
Use the /close command to mark a forum thread as answered
Accord
Accord15mo 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.
Want results from more Discord servers?
Add your server