Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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#_List - Fatal编程技术网

C# 列表将引用添加到字符串对象

C# 列表将引用添加到字符串对象,c#,list,C#,List,有没有这样的选择: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Student { public string PassPort { get; set; } public string FirstName { get; set; } public string Last

有没有这样的选择:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Student
{


    public string PassPort { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Message { get; set; }
    public List<string> AllProperties { get; set; }

    public Student()
    {
        AllProperties = new List<string>();
        AllProperties.Add(ref PassPort);
        AllProperties.Add(ref FirstName);
        AllProperties.Add(ref LastName);
        AllProperties.Add(ref Message);


    }

}
class Program
{
    static void Main(string[] args)
    {
        Student student = new Student();
        student[0] = "PASS";
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
班级学生
{
公共字符串PassPort{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共字符串消息{get;set;}
公共列表所有属性{get;set;}
公立学生()
{
AllProperties=新列表();
添加(参考护照);
AllProperties.Add(ref FirstName);
AllProperties.Add(ref LastName);
添加(参考消息);
}
}

因此,当我更改
AllProperties[0]
时,它将更改
PassPort
字符串变量???

我不确定您想要的是什么,但您可以使用索引器:

class Student
{
    public string PassPort { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Message { get; set; }

    public string this[int index]
    {
        get { throw new NotImplementedException(); }
        set
        {
            switch (index)
            {
                case 0:
                    PassPort = value;
                    break;
                case 1:
                    // etc.
                default:
                    throw new NotImplementedException();
            }
        }
    }
}
还有这样的用法:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Student
{


    public string PassPort { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Message { get; set; }
    public List<string> AllProperties { get; set; }

    public Student()
    {
        AllProperties = new List<string>();
        AllProperties.Add(ref PassPort);
        AllProperties.Add(ref FirstName);
        AllProperties.Add(ref LastName);
        AllProperties.Add(ref Message);


    }

}
class Program
{
    static void Main(string[] args)
    {
        Student student = new Student();
        student[0] = "PASS";
    }
}

是否希望所有属性[0]调用属性“PassProt”?如果是这样的话,你应该使用DataTable来显示信息,我想通过索引来执行我正在执行execl DataTable,我需要字符串作为属性,但消息属性是可选的,所以我想确保只有相关属性是fullfill,而不是为属性输入null我正在执行execl DataTable,我需要字符串作为属性属性,但是消息属性是可选的,所以我想确保只有相关属性是fullfill,而不是在属性中输入null