How can i declare a variable inside String.format and use it again like :
String.Format("{0} {1}", int t = 1, new string[] { "a", "b" }.ElementAt(t));
update
I just want to learn something new and type the code in one line.
It is not necessary in this case, but useful in others.
update
I found another solution :
int indx;
var st = String.Format("{0} {1}", (indx=1), new string[] { "a", "b" }.ElementAt(indx));
It would be good if you would share reason why you try to do it this way, and maybe tell us what are you working on.
Your code to work should look like this
int t = 1;
string[] myArray = new string[] { "a", "b" };
Console.WriteLine(string.Format("{0} {1}", t, myArray[t]));
What you are attempting to do seems to be without any sense, first of all it will not work. Doing stuff your way makes it impossible to access t and array you created and even if it worked it would be same as static string string myString = "1 b"
. Your way you make it impossible to manipulate these variables because they would only exist in context of that one line and would be back to their initial value when it gets executed each time.