"Method" is used as error "type" C #

So, I have this bit of code, which for some reason will not compile, because it says that I use the method as a type .... For some strange reason, I can’t understand what it means that this is wrong, the only article I gave me is an article that is less than useless.

So my question is: what's wrong with this code:

static void Main() {
    Application.Run(new stat_checker());
}
public stat_checker() {
}
+3
source share
7 answers

The function Application.Run();takes the form as an argument, for example: Application.Run(new Form1());

0
source

Well, you call newon it, so you want to declare a type with the name stat_checker:

public class stat_checker : Form
{
}

, stat_checker, :

Application.Run(stat_checker());

stat_checker :

public Form stat_checker() {
    // Return something here
}

stat_checker? , :

using System;
using System.Windows.Forms;

class stat_checker : Form {

    static void Main() {
        Application.Run(new stat_checker());
    }
    public stat_checker() {
    }
}

, , . .NET, . StatChecker stat_checker.

+10

:

public ??? stat_checker() {

}

stat_checker. , , , stat_checker.

+3

.

stat_checker , Form,

static void Main() {
    Application.Run(new stat_checker());
}

public class stat_checker : Form {
// TODO: Implement the class
}

stat_checker , Form new,

static void Main() {
    Application.Run(stat_checker());
}
public Form stat_checker() { 
// TODO: Code that creates and returns a Form.
}
0

stat_checker ; new ( ..) - .

stat_check - , Application.Run(new...) .

? , , .

0

, stat_checked , ApplicationContext, .

, :

class StatChecker : ApplicationContext
{
    public StatChecker()
    {
        Console.WriteLine("Hello, world!");
    }
}

:

Application.Run(new StatChecker());

Note that your StatChecker class must extend or return an ApplicationContext. The typical "Form" class, for example, extends ApplicationContext, so it works.

0
source

Could it be as simple as inconsistent namespaces. They must be the same in both classes in order to use the unqualified new stat_checker (). It bit me a bit when I got here ...; -)

0
source

Source: https://habr.com/ru/post/1792305/


All Articles