locked
How to assign an array structure to an array? RRS feed

  • Question

  • User1897897189 posted

    Dears,

    How to assign an array structure to an array?

    for example i have an array like the following
    private VS[] vLF;

    and i have a structure like
    public partial class VS: object, System..... {
    private string ID;

    }

    i want to assign VS to VS[]

    thanks

    Tuesday, December 3, 2019 9:28 AM

All replies

  • User-1780421697 posted

    I did not clearly understand your requirements

    using System;
    using System.Linq;
    public class Simple {
      public static void Main() {
       
    	VS[] vs = new VS[10];
    	vs[0] = new VS(){ ID="1"};
    	Console.WriteLine(vs[0].ID);  
    	  
      }
    	
    	public class VS
    	{
              public string ID{get;set;}
            }
    }


    however you can have a look on it. Result is=> 1

    Tuesday, December 3, 2019 9:53 AM
  • User1897897189 posted

    yes this is correct,

    sorry forgot to mention that i have list of values to be assigned

    so how can i assign it.

    Tuesday, December 3, 2019 10:15 AM
  • User-1780421697 posted

    You just need to identify at which position you want to add object and you ArrayName[Position] = new Object{};

    VS[] collection = new VS[2];
    collection [0] = new VS{....};
    collection [1] = new VS{....};
    
    
    OR
    
    List<VS> collection = new List<VS>();
    collection.Add(new VS{....});
    collection.Add(new VS{....});

    Tuesday, December 3, 2019 10:38 AM