What is the point of using set and get in C Sharp?
It seems variables are used differently in this language than in C++.
For some reason, you have to have a static variable defined like this:
public static uint Somenum
{
set { m_somenum = value; }
get { return m_somenum; }
}
and prior to this declaration, you need to have this:
public uint m_sumenum;
This seems to be the only way to expose a member of a class to other classes in C#.
The problem is that I seem to be doing this improperly because I get a compile error:
An object reference is required for the non-static field, metod, or property '.......m_somenum"
I think I see the problem. The problem is that I cannot use a static varable like this.
So you have to instantiate the class in order to set these members of the class.
So how would you do the equivalent of a global class in C Sharp?
Would I do it something like this:
public clase SomeClass
{
SomeClass someclass = new SomeClass();
public static uint Somenum
{
set { m_somenum = value; }
get { return m_somenum; }
}
}
Or perhaps this "new" needs to be outside of the class in order to work. So my next question is this. How and where would that command be such that it the internal set methods could be accessed by the other classes in the code?
Not such a great deal, Ultimate, which gives you full 5080 features is $181.99 CAD per month, that's $2183.88 per year, I can buy the 5080 for $1809.99 CAD, then it goes up to $279.99 per month after the first billing cycle. Typical cloud rental, costs more than buying the hardware.
Wow, spoken like a true blind hater, you don't even provide arguments. Please, go check my comment above to @seacaptain and you'll find out why what you say doesn't make sense in this context...
Get used to this, with AI tooling now uncovering new vulns and getting them exploitable far faster than has ever been possible before software is going to need to be updated far more frequently.
Back in the day it may take reseachers weeks or months to do what AI can now do in hours.
Once its a threat is discovered it's weaponsized far more quickly, meaning you simply can't be waiting 2, 3, 4 weeks to deploy a patch, it needs to be patched immediately.
Going to be interesting handling this in the enterprise space where traditionally patching has been steady, but very staged (and rightly so up until now), that is going to have to change.
Question
Complete
What is the point of using set and get in C Sharp?
It seems variables are used differently in this language than in C++.
For some reason, you have to have a static variable defined like this:
public static uint Somenum
{
set { m_somenum = value; }
get { return m_somenum; }
}
and prior to this declaration, you need to have this:
public uint m_sumenum;
This seems to be the only way to expose a member of a class to other classes in C#.
The problem is that I seem to be doing this improperly because I get a compile error:
An object reference is required for the non-static field, metod, or property '.......m_somenum"
I think I see the problem. The problem is that I cannot use a static varable like this.
So you have to instantiate the class in order to set these members of the class.
So how would you do the equivalent of a global class in C Sharp?
Would I do it something like this:
public clase SomeClass
{
SomeClass someclass = new SomeClass();
public static uint Somenum
{
set { m_somenum = value; }
get { return m_somenum; }
}
}
Or perhaps this "new" needs to be outside of the class in order to work. So my next question is this. How and where would that command be such that it the internal set methods could be accessed by the other classes in the code?
Link to comment
https://www.neowin.net/forum/topic/721934-using-set-and-get-in-c-sharp/Share on other sites
13 answers to this question
Recommended Posts