![does anyone know what these are? they looks like a constructor or a method? what are they?](https://i.redd.it/ibymc85b9w6d1.png)
does anyone know what these are? they looks like a constructor or a method? what are they?
Question![does anyone know what these are? they looks like a constructor or a method? what are they?](https://i.redd.it/ibymc85b9w6d1.png)
ahhh okay thank you, sorry i should of been more specific , but this is what i was asking. Im not too familiar with structs since i never use them
Structs are pretty similar to classes, but they're more used for storing data and creating functionally for classes to use. As a general rule, you won't see constructors used for Unity scripts.
if you're referring to:
return new GameAuthResponse
{
Code = someValue,
Player = someOtherValue,
Token = dotDotDot
};
that is pretty much the same as doing this:
GameAuthResponse myVar = new();
myVar.Code = someValue;
myVar.Player = someOtherValue;
myVar.Token = dotDotDot;
return myVar;
Are you talking about the get set things instead?
You mean the methods ? They're not constructors, they're static methods. They do return an instance of the class though, but as static methods you don't need an instance of said class to call them
Essentially you will indeed use them to "create" an instance of that class I guess
What exactly is your question ? Those are static methods.
I think ops question is about the overall pattern returning the same class after running the operation based on the inputs. These are called Factory Methods that work as an integral part of the factory pattern. They are generaly useful for controlling the creation process of an object, particularly when the creation logic is complex or involves multiple steps. https://en.m.wikipedia.org/wiki/Factory_method_pattern
For the full pattern, there is a more simplified version of this but the general approach helps keep you code cleaner and maybe create less errors I think.
I see Visual Studio theme with C# methods and properties.
Do you mean the struct
? Or is it the static
methods with the struct
as return type? Or are you confused by the { get; set; }
?
These are static methods that produce concrete types.
Static means you do not need an instance of the class to use these methods (they are always available in scope).
They are not constructors because constructors are contained within their classes and are called via the 'new <class>(params)' syntax.
These do behave like a constructor in that they are producing concrete types from input params.
This appears to be a form of the factory pattern.
Ask better questions. “these” and “they” are not specific enough, and you’ve posted too much code for people to understand which parts you are referring to.
Yes I will lol sorry, i think i was half awake when i made this post lol.
User deleted comment
21d
And my balls are huge
I never would've guessed
And you guys really went with downvoting this comment? Geez...
Which part are you talking about? It's just a struct that has methods to return the same type. Those aren't constructors.