Command_ReadLine1.htm
Objective :
  • error CS0029: Cannot implicitly convert type 'string' to 'string[]' : error CS0029: Cannot implicitly convert type 'string' to 'string[]'
  • Distinguish between : a variable and array of variables of same type [] array
  • Use of a LOOP /Iteration.
Source Code : Error CS0029: Cannot implicitly convert type 'string' to 'string[]'

// Namespace Declaration
//File location : C:\BareBone_CSharp\Source_Code\Template
using System;
//csc CsharpTemplate.cs
// Program start class
class CsharpTemplate
{
// Main begins program execution.
static void Main(string[] str1)
{
// Write to console
Console.WriteLine("Welcome to C#!");
Console.Write("what's your name :");
str1 = Console.ReadLine(); // won't compile
Console.WriteLine("Hi, {0}", str1);

}
}

Warning : CS0028 , error CS5001

// Namespace Declaration
//File location : C:\BareBone_CSharp\Source_Code\Template
using System;
//csc CsharpTemplate.cs
using System.Collections.Generic;
// Program start class
class CsharpTemplate
{
// Main begins program execution.
static void Main(string str1)
{
// must initialize the array
// Write to console
Console.WriteLine("Welcome to C#!");
Console.Write("what's your name :");
str1 = Console.ReadLine(); // won't compile
Console.WriteLine("Hi, {0}", str1);

}
}

Edit the above code :

// Namespace Declaration
//File location : C:\BareBone_CSharp\Source_Code\Template
using System;
//csc CsharpTemplate.cs
using System.Collections.Generic;
// Program start class
class CsharpTemplate
{
// Main begins program execution.
static void Main(string[] str1)
{

Console.Write(" U Entered {0} ", str1.Length);
Console.Write(" strings");
Console.WriteLine();
foreach (string arg in str1)
{
Console.Write(arg);
Console.Write(" ");

}
}
}