【发布时间】:2014-07-31 16:01:43
【问题描述】:
我有一个名为 SQL.cs 的文件,它看起来像这样(为简洁起见,查询已编辑):
using System.Collections.Generic;
public static class SQL
{
public static readonly Dictionary<string, string> SQL = new Dictionary<string, string>()
{
{"Customers", "SELECT * FROM customers"},
{"OverdueInvoices", "SELECT * FROM invoices WHERE overdue = true"},
};
}
来自Main.cs,我不得不像这样引用它:
new MySqlCommand(SQL.SQL["Customers"]);
如何消除第一个SQL? IE。我想使用:
new MySqlCommand(SQL["Customers"]);
【问题讨论】:
-
您最好使用资源文件,如果您使用 Winforms 则使用
resx文件,如果使用 WPF 则使用ResourceDictionary。