Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以将类属性方法参数设置为c吗_C# - Fatal编程技术网

C# 我可以将类属性方法参数设置为c吗

C# 我可以将类属性方法参数设置为c吗,c#,C#,我试图将类属性的名称传递给方法中的参数。目前,我正在复制方法并更改杂物属性和客户[I]属性。这种方法需要大约4次,所以最好只做一次会更整洁。然后,根据调用customer类的属性,我使用一个单一模式弹出窗口加载不同的表 如何使Customer类属性作为BindList方法中的参数可用 我在dictionary和func上看到过一些帖子,但不确定如何使用它们 *注:静态列表Cust 在另一种方法中:Cust=CustomerList public class Customer {

我试图将类属性的名称传递给方法中的参数。目前,我正在复制方法并更改杂物属性和客户[I]属性。这种方法需要大约4次,所以最好只做一次会更整洁。然后,根据调用customer类的属性,我使用一个单一模式弹出窗口加载不同的表

如何使Customer类属性作为BindList方法中的参数可用

我在dictionary和func上看到过一些帖子,但不确定如何使用它们

*注:静态列表Cust

在另一种方法中:Cust=CustomerList

   public class Customer
    {
        public string CustName { get; set; }
        public string CustPhone { get; set; }
        public string CustAddress { get; set; }
        public string CustHistory { get; set; }
    }
*另外:参数只是示例,因为我不知道该放什么

  public void BindLists(sundries.prop sundparm, Customer.prop custparm)
    {
        SundriesRepo sundries = new SundriesRepo();
        List<string> TempList = new List<string>();
        TempList = sundries.sundparm;

        lblEdit.Text = "History Edit";

        List<string> Used = new List<string>();
        List<string> NotUsed = new List<string>();

        if (Patients.Count > 0)
        {
            for (int i = 0; i < Cust.Count; i++)
            {
                string result = Cust[i].custparm;

                if (result != null)
                {
                    Used.Add(result);
                }
            }
            NotUsed = TempList.Except(Used).ToList();
        }

        listNotUsed.DataSource = NotUsed;
        listNotUsed.DataBind();
        listUsed.DataSource = Used;
        listUsed.DataBind();

        modPopExt1.Show();
    }
HTML是:

                <asp:Panel runat="server" ID="modPan" CssClass="modPan">
                    <div id="modPanHeader">
                        <asp:Label runat="server" ID="lblEdit"></asp:Label>
                    </div>
                    <div id="divfloat" class="divfloat">
                        <div id="divList" style="float: left" class="float">
                            <asp:ListBox runat="server" ID="listNotUsed" CssClass="listBox"></asp:ListBox>
                        </div>
                        <div id="divPatient" style="float: right" class="float">
                            <asp:ListBox runat="server" ID="listUsed" CssClass="listBox"></asp:ListBox>
                        </div>
                        <div class="divModPanBtnClose">
                            <asp:Button runat="server" ID="modPanBtnClose" Text="Close"/>
                        </div>
                    </div>
                </asp:Panel>
                <asp:ModalPopupExtender runat="server" ID="modPopExt1" PopupControlID="modPan" CancelControlID="modPanBtnClose" 
                    TargetControlID="lblEdit"></asp:ModalPopupExtender>

我无法写入要在字符串result=Cust[I].custparm处接受的参数

如果我理解正确,您会问是否可以将类的属性作为方法参数传递

当然可以。 或者简单地传递/使该方法期望一个客户实例

var prop1 = null;
var prop2 =null;
var prop3 = null;
var prop4 = null;

//Which ever prop gets value

public void BindLists(string prop1 = null, string prop2= null, string prop3 =null, string prop4 =null)
{
  //check which ever is not null
  //Since you say one of them will be having the value.
  enter rest code here
}


//calling side
Customer cust = new Customer();
BindLists(prop1 = value, prop2 = value, prop3=value, prop4 = value) //default will be null

这仍然需要我重写方法,以便每次都更改cust属性。我需要能够通过方法参数更改类属性。cust是将具有所有属性值的实例。我想列出属性值,因此我需要更改属性而不是cust。Cust.CustName,Cust.CustPhone等再次说明,您没有将类的属性作为方法参数传递,而是传递整个类。也许您可以使用可选参数和命名参数。