Search code examples
c#delegatesanonymous-methods

Anonymous methods and with some constant arguments


I have a function FUNC1(int a) and a function FUNC2(int a, int b). I have a delegate with a type of void() (no arguments). I want to have 2 variables. When I call one like this: VAR1() then FUNC1(4) will run. and VAR2 that will run FUNC2(2,9). I asked this yesterday, and I was told to use anonymous methods like this: VAR1 = () => FUNC1(4) and it works fine.

Now I want to do something a little more complicated. I have a new type of delegate void(int a). and I want a variable VAR3. When I call VAR3(5) I want to execute FUNC2(5,8). If I call VAR3(9) I want to execute FUNC2(9,8). So basically, the first argument can change, but the second argument is constant.


Solution

  • Well, that woulde be something like that:

    VAR3 = (x)=>FUNC2(x,8);