C#全局模块 [英] C# global module

查看:141
本文介绍了C#全局模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c#的新手,我想知道是否有人可以告诉我如何像在vb中那样创建一个用于更改表单的全局模块,然后如何调用该模块.

I'm new to c# and I was wondering if someone could tell me how to create a global module for changing a form like you would do in vb, and then how to call that module.

谢谢

更新:

好吧,所以我有多种形式,而不是一遍又一遍地写同样的两行.

Ok so i have multiple forms and instead of writing the same 2 lines over and over, which are..

Form x = new Form1();
x.Show();

是否可以将其添加到类中以使其变得更容易.我该怎么做?从来没有上过课.上了课,但不确定如何编写代码.

Is it possible to add this to a class to make it easier. How do i do it? never made a class before. got the class up but unsure how to write the code.

推荐答案

在C#中没有什么是全局模块,而是可以创建具有静态成员的Public类,例如:

There is nothing as Global Module in C# instead you can create a Public class with Static Members like:

//In a class file 

namespace Global.Functions //Or whatever you call it
{
  public class Numbers
  {
    private Numbers() {} // Private ctor for class with all static methods.

    public static int MyFunction()
    {
      return 22;
    }
  }
}

//Use it in Other class 
using Global.Functions
int Age = Numbers.MyFunction();

这篇关于C#全局模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆