[英]convert VB.net Module to C#
I decided to try out C# for the first time after using VB.net. 我决定在使用VB.net之后第一次尝试C#。
Out of curiousity, when I used VB.net I had : 出于好奇,我在使用VB.net时遇到了:
Dim conn As OleDbConnection = New OleDbConnection("Provider=""****"";user id=" & strUserID & ";data source=" & strDatabase & ";password=" & strPssWd)
When trying to convert this format to C# I did the following: 当尝试将此格式转换为C#时,我执行了以下操作:
string strAccessConn = "Provider=****;user id=" & strUserID & ";data source=" & strDatabase & ";password=" & strPssWd
However, my strUserId, strDatabase and strPssWd where saved in my Module.vb for VB.net like so: 但是,将我的strUserId,strDatabase和strPssWd保存在VB.net的Module.vb中,如下所示:
Module Module1
Friend strDatabase As String = "****"
Friend strUserID As String = "****"
Friend strPssWd As String = "****"
End Module
How do I make the Module in C# (an example would be helpful) Thanks! 我如何在C#中制作模块(一个示例会有所帮助)谢谢!
FYI: I was told C# Equivalent for VB 'module' was a duplicate. 仅供参考:我被告知VB“模块”的C#等效项是重复项。
However the formatting and process of their post isn't equivalent to mine. 但是,他们的帖子的格式和过程与我的不同。 I am asking a module based on database connection. 我问一个基于数据库连接的模块。
You can put constants in a public static class
like this: 您可以将常量放在这样的public static class
:
public static class MyConnectionStringConstants
{
public const string strDatabase = "****";
public const string strUserID = "****";
public const string strPssWd = "****";
}
To use it, you will need to refer to the constants like this: 要使用它,您将需要引用如下常量:
string strAccessConn = "Provider=****;user id=" + MyConnectionStringConstants.strUserID + ";data source=" + MyConnectionStringConstants.strDatabase + ";password=" + MyConnectionStringConstants.strPssWd
BTW, in C#, you concatenate strings using the +
operator, not the &
operator. 顺便说一句,在C#中,您使用+
运算符而不是&
运算符来连接字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.