❔ 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
Angius
REPL Result: Success
Console Output
Compile: 640.475ms | Execution: 81.193ms | React with ❌ to remove this embed.
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
Angius
REPL Result: Success
Result: int
Compile: 250.586ms | Execution: 23.895ms | React with ❌ to remove this embed.
i see
thanks
that was dumb
$close
Use the /close command to mark a forum thread as answered
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.