Inside variable which is of string type i am storing integer value without any conversion and again i am displaying it. what is reason behide it? why i am not getting any error if i am storing interger value in string datatype in c# for console application
You have to specify conditions for accepting string only. We can use inbuilt function for that or can develop our logic to force to user for entering string or characters only.
class Program { static void Main(string[] args) { string s; Console.WriteLine("enter interger value"); s = Console.ReadLine(); Console.WriteLine(s); Console.ReadLine(); } }
Your input never converted to integer. Console.ReadLine() returns string which is stored in string and then Console.WriteLine() can show string that's y it is working. You have to explicitly do integer conversion from Console.ReadLine()