© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
25 replies
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;
    }
}
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
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"),
    ...
]
Example[] ArrayOfExamples = [
    Example(id: 1, name: "hi"),
    ...
]
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ how to check attribute name?
C#CC# / help
2y ago
Set a class attribute result with a custom attribute
C#CC# / help
3y ago
Api Method Name Attribute
C#CC# / help
2y ago
❔ Generally, how do you implement a readonly struct?
C#CC# / help
4y ago