Bone
Bone

Reputation: 907

How to call a callback with arguments C#

Here I am again with another question about C#.

So,here are some of the files i have in my project.

Configuration.cs
Settings1.cs
Bot.cs

Now, the problem is, in Settings1.cs I have made a callback (If that is what you call it in C#).

public void LoadText(Configuration.BotInfo config)
{
    txtUsername.Text = config.Username;   
    txtPassword.Text = config.Password;
    txtName.Text = config.DisplayName;
    txtPrefix.Text = config.DisplayNamePrefix;
    txtBackpack.Text = config.Backpack;
    txtSell.Text = KeyUserHandler.SellPricePerKey.ToString();
    txtBuy.Text = KeyUserHandler.BuyPricePerKey.ToString();
    lblPrice.Text = value.ToString();    
}

As you can see, it is getting the data from the Configuration.cs file. What I want to do, is that I wanna call this under the Settings1_Load callback.

So, when I type

LoadText();

It gives me the error that it cannot have 0 arguments.. But what argument can I use here? I am only kind of 'dimming' Configuration.BotInfo as config because if I use the full name everywhere, it gives me the non-static and static field error.

Upvotes: 2

Views: 201

Answers (1)

Selman Genç
Selman Genç

Reputation: 101681

No, it is not getting data from Configuration.cs file, it is getting data from that argument which is named config and the type of argument is Configuration.BotInfo. Probably BotInfo is a class which is defined inside of your Configuration.cs file.You should pass a BotInfo instance to your function to make it work.

For example you can call your method like this:

                                // set your  other properties
LoadText(new BotInfo { Username = "user2331", Password="1234", ... })  

Upvotes: 1

Related Questions