Tengo algo de código para inicializar un struct en C#:Cómo inicializar un struct en C#
namespace Practice
{
public struct Point
{
public int _x;
public int _y;
public int X
{
get { return _x; }
set { _x = value; }
}
public int Y
{
get { return _y; }
set { _y = value; }
}
public Point(int x, int y)
{
_x = x;
_y = y;
}
}
class Practice
{
public static void Main()
{
Point p1;
p1.X = 1;
p1.Y = 2;
}
}
}
El código anterior da un error del compilador:
error CS0165: Use of unassigned local variable 'p1'
¿Por qué se está lanzando este error?
Esto es en realidad uno de mis mani fi esta en C#. Cualquier variable local debe inicializarse a 'IMO 'predeterminada. – leppie