problem with string datatype in c# 2.0

Discussion in 'Programming' started by sheetal_kawade, Nov 23, 2010.

  1. #1
    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
     
    sheetal_kawade, Nov 23, 2010 IP
  2. longcall911

    longcall911 Peon

    Messages:
    1,672
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    0
    #2
    We need to see some code.

    Most likely, your integer is a string already and not an int.
     
    longcall911, Nov 23, 2010 IP
  3. yashsaxena

    yashsaxena Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    yashsaxena, Nov 24, 2010 IP
  4. hassanjawed

    hassanjawed Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    post your code.
     
    hassanjawed, Nov 26, 2010 IP
  5. sheetal_kawade

    sheetal_kawade Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5

    class Program
    {
    static void Main(string[] args)
    {
    string s;
    Console.WriteLine("enter interger value");
    s = Console.ReadLine();
    Console.WriteLine(s);
    Console.ReadLine();
    }
    }
     
    sheetal_kawade, Dec 3, 2010 IP
  6. hassanjawed

    hassanjawed Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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()
     
    hassanjawed, Dec 3, 2010 IP