简体   繁体   中英

'Autoclicker' is namespace but is used like a type

I am trying to make autoclicker but i get this error

image of program.cs file

my whole Autoclicker.cs file -> https://controlc.com/16cd5eb4

now i got new error.

Error CS1503 Argument 1: cannot convert from 'Autoclicker.Autoclicker' to 'System.Windows.Forms.Form'

https://i.imgur.com/vT1vy1N.png

I suppose there is a class named AutoClicker under project AutoClicker (default namespace). In this case, you need to provide the fully qualified name of the class AutoClicker . It means combination between namespace and class name.

namespace AutoClicker
{
    internal class Client
    {
        private void TestMethod()
        {
            var autoClicker = new AutoClicker.AutoClicker();
        }
    }
}

AutoClicker.cs

namespace AutoClicker
{
    public class AutoClicker
    {
        // Implementation
    }
}

This may be a little late, but I did not see any answers that addressed the actual issues. I will go ahead and post an answer for any future searchers landing on this question.

In your original "image of program.cs file" you have a closing curly bracket on line number 10 (it's still present on line 16 of the edited program.cs file as well) - this puts your main method outside of the Autoclicker namespace.

Once you have corrected that, your Autoclicker.cs class is declared in a separate namespace:

namespace autoclicker

Namespaces are case sensitive, so you will need to fix that as well - or you will have to qualify your instance as:

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new autoclicker.Autoclicker());
    }

(note: qualifying the instance will only work if the Autoclicker.cs class namespace and the Autoclicker.Designer.cs class namespace match as described below)

The current error message you are getting is due to the class declared in the Autoclicker.cs file is actually named Combat:

public partial class Combat : Form

Either change that name to Autoclicker or update your Autoclicker.Designer.cs file class name to match:

Autoclicker.cs:

public partial class Autoclicker : Form

Autoclicker.Designer.cs:

partial class Autoclicker

-OR-

Autoclicker.cs:

public partial class Combat : Form

Autoclicker.Designer.cs:

partial class Combat

If these two class names are different AND/OR the namespaces they are contained in are different, the partial class feature will not auto combine them into one class - that is why you are getting the current error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM