+ 2
i Need Help
check this code : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { class point { public point(int x,int y) { Console.WriteLine(
quot;point p1 located in ({x},{y})"); } } static void Main(string[] args) { point p1 = new point(4,5); point p2 = new point(2,3); } } } when i call p1 i get in outputs :point p1 located in (4,5) and the problem when i call p2 i get in output: point p1 located in (2,3) and i want to change that p1 in console.writeline into p2 how to do that using constructors ??1 Antwort
+ 2
If you want to do that you have to add a name parameter
class point
{
public point(int x,int y, string pointname)
{
Console.WriteLine(quot;point {pointname} located in ({x},{y})");
}
A object does know its own type but not its own name.