List add a ref to string object

Asaf Shazar

Is there any option to do something like this:

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);


    }

}

so when I change the AllProperties[0] it will change the PassPort string variable???

Peter van der Heijden

I am not really sure what it is you are after, but you might be able to use an indexer:

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();
            }
        }
    }
}

And the use that like this:

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

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Add string to List<string>

분류에서Dev

Deserializing Xml string into object with List<>

분류에서Dev

List <Tuple <string, List <Object >>> 병합

분류에서Dev

add files to List(String) in certain order

분류에서Dev

List <Map <String, Object >> to List <Map <String, Object >> group by key with nulls

분류에서Dev

List <IDictionary <string, object >> 추가 추가 List <IDictionary <string, object >> with title

분류에서Dev

Dictionary <string, object> 대 List <string> + BinarySearch의 성능

분류에서Dev

Add an object to a list within a method, no matter what type they are

분류에서Dev

Is it possible to add list of object to change state of Entity Framework

분류에서Dev

Is it better to handle object creation inside the function or add it to the parameter list

분류에서Dev

List <List <object >>를 List <List <string >>으로 변환

분류에서Dev

Map <String, Object>를 Map <String, List <Object >>로 변환

분류에서Dev

i cant add data from sql to list of string

분류에서Dev

C # LINQ 쿼리 a List <Dicitonary <string, object >>

분류에서Dev

ItemsSource가 List <Dictionary <string, object >> 인 ListBox

분류에서Dev

Perl - can't use string (...) as an array ref

분류에서Dev

List <object> 유형의 개체를 List <string>으로 변환

분류에서Dev

c #-List <string>의 항목을 List <object>에 넣는 방법

분류에서Dev

Generics :`List <String>`을`List <Object>`에 추가합니다.

분류에서Dev

List <List <Object >> to String [] []. 방법이 있습니까?

분류에서Dev

List <string> 및 List <Object>를 사전에 삽입

분류에서Dev

Add a list in a list

분류에서Dev

Java Small Map <String, List> vs Large Map <Object, String> 성능

분류에서Dev

foreach list <object> in object

분류에서Dev

C # 'ref xxx'에서 'ref object'로 변환 할 수 없습니다.

분류에서Dev

LINQ를 사용하여 Dictionary <int, List <Tuple <string, object >>>에서 Dictionary <int, List <Tuple <string, object, AnEnum >>>으로

분류에서Dev

List <string> to string [,]

분류에서Dev

.add () 항목이 아닌 list <string>의 클래스 생성자

분류에서Dev

List <String []>을 Java의 Object [] [] 2d 배열로 변환

Related 관련 기사

  1. 1

    Add string to List<string>

  2. 2

    Deserializing Xml string into object with List<>

  3. 3

    List <Tuple <string, List <Object >>> 병합

  4. 4

    add files to List(String) in certain order

  5. 5

    List <Map <String, Object >> to List <Map <String, Object >> group by key with nulls

  6. 6

    List <IDictionary <string, object >> 추가 추가 List <IDictionary <string, object >> with title

  7. 7

    Dictionary <string, object> 대 List <string> + BinarySearch의 성능

  8. 8

    Add an object to a list within a method, no matter what type they are

  9. 9

    Is it possible to add list of object to change state of Entity Framework

  10. 10

    Is it better to handle object creation inside the function or add it to the parameter list

  11. 11

    List <List <object >>를 List <List <string >>으로 변환

  12. 12

    Map <String, Object>를 Map <String, List <Object >>로 변환

  13. 13

    i cant add data from sql to list of string

  14. 14

    C # LINQ 쿼리 a List <Dicitonary <string, object >>

  15. 15

    ItemsSource가 List <Dictionary <string, object >> 인 ListBox

  16. 16

    Perl - can't use string (...) as an array ref

  17. 17

    List <object> 유형의 개체를 List <string>으로 변환

  18. 18

    c #-List <string>의 항목을 List <object>에 넣는 방법

  19. 19

    Generics :`List <String>`을`List <Object>`에 추가합니다.

  20. 20

    List <List <Object >> to String [] []. 방법이 있습니까?

  21. 21

    List <string> 및 List <Object>를 사전에 삽입

  22. 22

    Add a list in a list

  23. 23

    Java Small Map <String, List> vs Large Map <Object, String> 성능

  24. 24

    foreach list <object> in object

  25. 25

    C # 'ref xxx'에서 'ref object'로 변환 할 수 없습니다.

  26. 26

    LINQ를 사용하여 Dictionary <int, List <Tuple <string, object >>>에서 Dictionary <int, List <Tuple <string, object, AnEnum >>>으로

  27. 27

    List <string> to string [,]

  28. 28

    .add () 항목이 아닌 list <string>의 클래스 생성자

  29. 29

    List <String []>을 Java의 Object [] [] 2d 배열로 변환

뜨겁다태그

보관