© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
111 replies
axo

null check raising errors

i come from python and my first interpretation was that they can work like decorators, but that's clearly not the case.

my question is how do i modify class data with an attribute?

like how in python you can decorate a class like this:
def change(name, value):
    def wrapper(cls):
        setattr(cls, name, value)
        return cls

    return wrapper

# ...

@change("num", 4)
class MyClass:
    def __init__(self):
        self.num = 10

mc = MyClass()
print(mc.num) # prints 4 and not 10
def change(name, value):
    def wrapper(cls):
        setattr(cls, name, value)
        return cls

    return wrapper

# ...

@change("num", 4)
class MyClass:
    def __init__(self):
        self.num = 10

mc = MyClass()
print(mc.num) # prints 4 and not 10


how would i do this in C#?
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
Next page

Similar Threads

Null check
C#CC# / help
15mo ago
How to check options for null?
C#CC# / help
3y ago
✅ How to automatically check for null?
C#CC# / help
3y ago