✅ How to do the C# equivalent of passing an std::function into a class
Hi, so I'm trying to make a class function that can accept a function of type float(float). I don't really understand how C# works because I'm coming from C++, which is very different than C# besides the names of data types. I've heard of delegates, but in all instances of a delegate parameter I've seen it as a pointer. Is a pointer bad C# syntax though in this case, since I'm trying to learn how to write C# well versus writing C# like C++. thanks in advance
12 Replies
Action
or Func
how is that not on the first page of bing 😭
thanks
whats the point of delegate then at that point
With a delegate you can type those funcs and actions
In the case above, you don't get any description of what that int is, for example
But you can define
and use that
so the Func could come out as an int with a string parameter instead?
doesnt matter for my current setup cuz of my data types but
What do you mean?
Yes, you can make the params and return type anything
If that's what you're asking
is that what you mean by not knowing what the int is?
No, you defined the
func
as something that takes an int and returns a string
Not the other way around
And what I mean is that the int
has no name here
It's just that, an int
You don't know if it's age, weight, or number of eggs in a basket
An explicit delegate
declaration lets you name all the params as you see fitoh ok
Lets you even write doc comments for it
So you get more help from the IDE
dubs i get it now
thanks
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Use the /close command to mark a forum thread as answered