如何将2个参数传递给方法/函数? [英] How do I pass 2 params to method/function?
问题描述
我最近遇到了死胡同,我一直在尝试创建一个可以处理插入,删除,打开连接,关闭连接等的MySql类...我做了一个函数来返回INSERT字符串, INSERT字符串是从pass paramaters / arguments编译的,死胡同是为了使这项工作我必须在2个params数组中传递列名和值,我知道这是不可能的,也无法想到这样做的任何其他方式。
I've recently hit a dead end, I've been trying to make a MySql class that would handle the Insert, Delete, Open Connection, Close Connection etc... I made a function to return the INSERT string, the INSERT string is compiled from the pass paramaters/arguments, the dead end is that to make this work I would have to pass in 2 params arrays for the column names and the values, I know that this is not possible and can't think of any other way of doing this.
private string genInsertString(string tableName, params string[] columnNames)
{
string query = "INSERT INTO " + tableName + " (" + String.Join(", ", columnNames) +"), VALUES(" + + ")";
return query;
}
如果你能帮助我,我将非常感激。谢谢
If you could help me I would be very grateful. Thanks
推荐答案
将包含参数名称和值的字典作为键/值传递,而不是使用当前的方法。
Pass a dictionary containing the parameter names and values as key/value instead of using your current approach.
你还可以创建一个小类,它具有ParamName的公共属性和ParamValue的另一个公共字符串,然后使用List<>你的班级。
You could also create a small class that had a public property for ParamName and another public string for ParamValue and then have it take a List<> of your class.
这篇关于如何将2个参数传递给方法/函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!