C#C
C#3y ago
10 replies
yz

C++ struct initializing in C#

in C++, we can do this -
struct Foo
{
  int A;
  int B;
};
Foo a = { 5, 7 };
std::cout << a.A; // 5
std::cout << a.B; // 7

But I found that I can't do this in C#. Do I have to assign values by each one like this?
a.A = 5;
a.B = 7;

I want to know how to assign member values simply in C#.
Was this page helpful?