How can I store a string command line argument in to a self defined string variable. As it tend to give "Array Index out of Range Bounds"...
Here is the code,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Prac1_e
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a String and a number : ");
Console.Read();
string str = args[0];
int n = Convert.ToInt32(args[1]);
Console.WriteLine(str);
Console.WriteLine(n);
Console.ReadKey();
}
}
}
argwhich has value when you execute your program with arguments in command line. When you want run-time arguments, you have to read fromConsole.Read();itself. It has a return type of string.ReadLine?=!