❔ Learning C#, and curious about advanced return statements...
I'm jumping right into the depts and wish to return a new object of 'Buffer' type and construct it with lambda.
The instruction should be to create
Buffer
object and write .txt file to Buffer.contents.
Can someone teach me how to make that happen with a single statement?
(new to C#, so please be gentle)17 Replies
this seems not that beginner friendly for c#
you can't pass a File as a parameter, it's static
you can probably pass a path
and then do
var file = File.ReadAllBytes(path);
this will give you a byte arrayIf you are looking a class that can be initialized with parameter as lambda, that means constructor is accepting a delegate/action
also the built-in type Buffer is static
for example
you can't instantiate it
and it's pretty stupid to have a struct for it
which is just an string array
you might aswell just have an string array only
same example without lambda
Yes, it is probably pretty stupid. The intention was as an example, but thank you.
And okay, I see. Thanks!
forget about simple statements, they are hard to understand
if they are not a requirement
also the built-in Buffer is enough
for your needs
The question wasn't so much related to "buffer" type, but to whether it was possible to instantiate a new object, like in Golang you do:
for example
you can, as long as it's not declared as static
Ah, yeh that makes sense.
the built-in Buffer and File can't be instantiated
think of them as extensions
like
File.ReadAllBytes
Yes, i understand you
and Buffer.GetX
Yeh, thanks! I understood m8 😉
for simplicity:
static = belongs to the type
non static = specific object
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.