-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
  • 5
  • 36

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,671
  • 1
  • 11
  • 24
0
string[] arr = new string[] {Lin1, Lin2};
vivek nuna
  • 16,885
  • 12
  • 74
  • 152
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
  • 13,574
  • 5
  • 47
  • 66