我有一堂课
public class TextBoxConfig
{
public string Caption { get; set; }
public string FieldName { get; set; }
public int Width { get; set; }
public string Name { get; set; }
}
和另一个实用程序类,它有一个接受 TextBoxConfig 作为参数的方法,像这样
public class Util
{
public static TextBox ApplySettings(TextBoxConfig config)
{
//Doing something
}
}
一般来说,我可以像这样调用 Util 类 ApplySettings 方法
TextBoxConfig config = new TextBoxConfig();
config.Caption = "Name";
config.FieldName = "UserName"
config.Width = 20;
config.Name = "txtName";
TextBox txt = Util.ApplySettings(config);
但我想像这样将参数传递给 ApplySettings
TextBox txt = Util.ApplySettings(o =>
{
o.Caption = "Name";
o.FieldName = "UserName"
o.Width = 20;
o.Name = "txtName";
});
请建议我该怎么做..