静态类必须从对象派生(C#) [英] Static classes must derive from object (C#)
本文介绍了静态类必须从对象派生(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有在C#中的一个问题,输出状态:
错误1静态类'WindowsFormsApplication1.Hello2'
不能从类型System.Windows.Forms.Form中派生。静态类
必须从对象派生。
我怎么能解决这个?
命名空间WindowsFormsApplication1
{
公共部分Form1类:表格
{
公共Form1中()
{
的InitializeComponent( );
}
私人无效的button1_Click(对象发件人,EventArgs五)
{
Hello2.calculate();
}
}
公共类您好:表
{
公共字符串测试{搞定;组; }
}
公共静态类Hello2:表
{
公共静态无效的计算()
{
的Process.Start(TEST.EXE);
}
}
解决方案
这意味着静态
类不能有:BaseClass的
在声明中。他们无法从任何继承。 (从 System.Object的
的继承是通过声明没有隐式的。)
A 静
类只能有静态
成员。只有实例成员都是继承的,因此继承是无用的静态
类。所有你需要做的就是删除:表格
I am having a problem in C#, the output states:
Error 1 Static class 'WindowsFormsApplication1.Hello2'
cannot derive from type 'System.Windows.Forms.Form'. Static classes
must derive from object.
How could I correct this?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Hello2.calculate();
}
}
public class Hello : Form
{
public string test { get; set; }
}
public static class Hello2 : Form
{
public static void calculate()
{
Process.Start("test.exe");
}
}
解决方案
It means that static
classes can't have : BaseClass
in the declaration. They can't inherit from anything. (The inheritance from System.Object
is implicit by declaring nothing.)
A static
class can only have static
members. Only instance members are inherited, so inheritance is useless for static
classes. All you have to do is remove : Form
.
这篇关于静态类必须从对象派生(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文