Cześć
Mam przykładową strukturę:
struct TestowaStruktura
{
public int x;
public int y;
}
Chcę przypisać do zmiennych wartości:
TestowaStruktura ts = new TestowaStruktura
{
x = 1,
y = 5
};
Z tego co znalazłem w książce to powinno się to dać zrobić też w taki sposób:
TestowaStruktura t2 = {2, 6};
Albo nawet tak:
TestowaStruktura t2 {2, 6};
Dostaję komunikat, że muszę użyć wyrażenia "new".
Gdzie robię błąd?
Cały kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
struct TestowaStruktura
{
public int x;
public int y;
}
static void Main(string[] args)
{
Console.WriteLine("test");
TestowaStruktura ts = new TestowaStruktura
{
x = 1,
y = 5
};
Console.WriteLine(ts.x + " " + ts.y);
TestowaStruktura t2 = {2, 6};
}
}
}