c#中字符串类型的列表
本文关键字:列表 类型 字符串 | 更新日期: 2023-09-27 18:14:03
我有一个列表
List<string> ParamValues = new List<string>();
ParamValues.Add(txtEmployeeId.Text);
ParamValues.Add(txtPassword.Text)
在Login.aspx.cs文件中。
我想使用这个列表作为一个方法的参数。该方法位于DataAccess.cs类文件中。我该怎么做呢?
假设该方法声明为接受的List<string>
(或IList<string>
等),您只需使用ParamValues
变量作为参数调用该方法:
DataAccess.SomeMethod(ParamValues);
调用实例方法:
DataAccess data = new DataAccess();
data.SomeMethod(ParamValues);
(顺便说一下,我会重命名变量-在PascalCase中看到c#变量是不寻常的。)
现在如果你有实际上就像这样:
public void SomeMethod(string id, string password)
如果方法是
public void MyMethods(System.Collections.Generic.List<string> paramValue)
{
//Write your code here
}
叫它
DataAcess da= new DataAcess();
da.MyMethods(ParamValue)
您只需将此列表作为参数传递,就像处理普通变量一样。
创建字符串类型的列表
List<string> paramValues = new List<string>();
将字符串添加到列表中并传递给DBAccess方法
让DataAccess.cs文件中的方法接受一个列表作为参数。
public void MyMethod(List list)
{
}