C#C
C#17mo ago
axo

✅ How do I set a struct attribute to its parameter name?

Doing this doesn't work.
public struct Example
{
    public int id;
    public string name;

    public Example(int id, string name)
    {
        id = id;
        name = name;
    }
}


I'm looking for something like a dataclass that just holds attributes I set once and read off continuously.

Looking for something like this:
from dataclasses import dataclass

@dataclass
class Example:
    id: int
    name: str


And then to be able to add a bunch to an array:
Example[] ArrayOfExamples = [
    Example(id: 1, name: "hi"),
    ...
]
Was this page helpful?