The request message was already sent. Cannot send the same request message multiple times

You are calling the same func parameter twice: var response = await ProcessRequestAsync(func); //… response = await ProcessRequestAsync(func); In this case func returns the same request every single time. It doesn’t generate a new one every time you call it. If you truly need a different request each time then func needs to return a … Read more

Can someone explain what the C# “Func” does?

A Func<int, string> like Func<int, String> pageUrl = i => “Page” + i; is a delegate accepting int as its sole parameter and returning a string. In this example, it accepts an int parameter with name i and returns the string “Page” + i which just concatenates a standard string representation of i to the … Read more

How can I pass in a func with a generic type parameter?

You cannot have instances of generic functions or actions – all type parameters are defined upfront and cannot be redefined by the caller. An easy way would be to avoid polymorphism altogether by relying on down-casting: public void SomeUtility(Func<Type, object, object> converter) { var myType = (MyType)converter(typeof(MyType), “foo”); } If you want type safety, you … Read more

void Func without arguments

Your wording is confusing. You perhaps mean “a function without a return type and no parameters.” There is simply System.Action. Action action = () => Console.WriteLine(“hello world”); action(); From your comment: But I need to fill in a <T> type in an Action and void is not a possibility (I will edit my question, I … Read more

Array and slice data types

See “Slices: usage and internals” var av = []int{1,5,2,3,7} That is a slice, not an array. A slice literal is declared just like an array literal, except you leave out the element count. That explains why the sort function will modify the content of what is referenced by the slice. As commented below by Kirk, … Read more

Can you get a Func (or similar) from a MethodInfo object?

This kind of replaces my previous answer because this, although it’s a slightly longer route – gives you a quick method call and, unlike some of the other answers, allows you to pass through different instances (in case you’re going to encounter multiple instances of the same type). IF you don’t want that, check my … Read more

Func delegate with ref variable

It cannot be done by Func but you can define a custom delegate for it: public delegate object MethodNameDelegate(ref float y); Usage example: public object MethodWithRefFloat(ref float y) { return null; } public void MethodCallThroughDelegate() { MethodNameDelegate myDelegate = MethodWithRefFloat; float y = 0; myDelegate(ref y); }

How do you use Func and Action when designing applications?

They’re also handy for refactoring switch statements. Take the following (albeit simple) example: public void Move(int distance, Direction direction) { switch (direction) { case Direction.Up : Position.Y += distance; break; case Direction.Down: Position.Y -= distance; break; case Direction.Left: Position.X -= distance; break; case Direction.Right: Position.X += distance; break; } } With an Action delegate, you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)