且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#.net Windows应用程序中将值从Windows窗体传递到类文件。

更新时间:2023-12-06 11:53:40

创建一个以连接字符串作为参数的构造函数。





Create a constructor that takes the connection string as a parameter.


public class classfile
{
    private string _connectionString;
    public classfile(string connectionString)
    {
        _connectionString = connectionString;
    }
}





现在你班上的任何地方都可以使用'_connectionString'成员。 (如果方法不是静态的)



无论你实例化你的类文件类,你都必须传递连接字符串。



Now everywhere in your class you can use the '_connectionString' member. (if the methods aren't static)

And everywhere you instantiate your classfile class you'll have to pass the connectionstring.