-1

I have string values seperately and want them to insert into an array. For example

var Lin1="te1";
var Lin2="te2";

I want to insert this into an arry value and want them to use it by array index. ie. for array[0]="te1", array[1]="te2"..

How can we achieve this? Thanks in advance...

KaviSuja
  • 450
  • 1
  • 9
  • 37

3 Answers3

1

You can declare the contents of an array when you initialise it like so

string[] LinArray = new string[] { Lin1, Lin2 };
Alfie Goodacre
  • 2,753
  • 1
  • 13
  • 26
0
string[] arr = new string[] {Lin1, Lin2};
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
0

You can use a List for this, if the number is not known beforehand.

 var list = new List<string>() { "te1", "te2"};
 list[0] = "te3";
Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67