user2923492
user2923492

Reputation: 5

Does anybody know why this line of c# coding is giving me an error?

so i was wondering why this code is giving me a problem?

this.adminList.Invoke((Delegate)(() => this.adminList.Items.Add((object)this.arg2)));

The error that it is giving me is:

Error 1 Cannot convert lambda expression to type 'System.Delegate' because it is not a delegate type

Does anybody know why this is happening? Oh, and btw when i try to do just simply adminList.Items.Add(arg2); it gives me an error when i try, something with 'cross thread not used on the thread it was created on' But anyways, arg2 is like the "username", and adminList is a listbox. This is c#. Thank you for your help and time :D P.S. It would be very helpful if you could revise this, thanks!

P.S.S: More code by request

            if (this.str.StartsWith("!addadmin") || this.str.StartsWith("!admin"))
            {
                if (Enumerable.Contains<char>((IEnumerable<char>)this.str, this.space))
                {
                    if (this.arg2 == this.names[m.GetInt(0U)])
                        con.Send("say", new object[1]
        {
          (object) (this.names[m.GetInt(0U)].ToUpper() + ": You can't make yourself an admin.")
        });
                    else if (this.mods.Contains((object)this.names[m.GetInt(0U)]))
                    {
                        if (this.names.ContainsValue(this.arg2))
                        {
                            if (!this.adminList.Items.Contains((object)this.arg2))
                            {
                                if (this.adminList.InvokeRequired)
                                    this.adminList.Invoke((Delegate)(() => this.adminList.Items.Add((object)this.arg2)));
                                con.Send("say", new object[1]
            {
              (object) (this.names[m.GetInt(0U)].ToUpper() + ": " + this.arg2.ToUpper() + " is added as an admin.")
            });
                            }
                            else
                                con.Send("say", new object[1]
            {
              (object) (this.names[m.GetInt(0U)].ToUpper() + ": " + this.arg2.ToUpper() + " is already an admin...")
            });
                        }
                        else
                            con.Send("say", new object[1]
          {
            (object) (this.names[m.GetInt(0U)].ToUpper() + ": " + this.arg2.ToUpper() + " doesn't exist in this world.")
          });
                    }
                    else
                        con.Send("say", new object[1]
        {
          (object) (this.names[m.GetInt(0U)].ToUpper() + ": You need to be a mod or the owner to use \"" + this.arg1 + "\"")
        });
                }
                else
                    con.Send("say", new object[1]
      {
        (object) ( this.names[m.GetInt(0U)].ToUpper() + ": Use it like: \"" + this.arg1 + " USERNAME\"")
      });
            }

names is a dictionary which stores usernames, mods are a list of ppl who have more power than admins, m is a PlayerIOClient.Message, arg1 is the 1st word said, str is the string in which the text when the user talks

Like i said earlier, adminList is a listbox

Upvotes: 0

Views: 112

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292405

A lambda expression cannot be inferred to a specific delegate type (since there could be several delegates with matching signatures), so you need to specify the delegate type explicitly. Delegate is not a concrete delegate type, it's just a base class for all delegates, so you can't use it.

In your case, you can use the Action delegate:

this.adminList.Invoke(new Action(() => this.adminList.Items.Add(this.arg2)));

Upvotes: 5

Related Questions