hello every one...

i'm very new to c#

in the following program (Console application prg.)

i want to get "int" value

of "eno","ph_no" in place of string type


but i don't know how to convert string type to "int"

type

if i use like

eno=(int)console.readLine();

then it will give error like "implicit conversion error"

i have search so many web site but i can't get proper answer

so please help me to solve it out

using System;

class emp
{
    string ename,eno,ph_no;
    //int eno,ph_no;

    public void get_data()
    {

    
        Console.WriteLine("\n\nEnter Employee Number :");
        eno = Console.ReadLine();//want int value ???
        Console.WriteLine("\nEnter The Employee Name: ");
        ename = Console.ReadLine();
        Console.WriteLine("\nEnter The Employee Ph. No: ");
        ph_no  = Console.ReadLine();//want int value ??

    }

    public void put_data()
    {
        Console.WriteLine("---------------------------------------------");
        Console.WriteLine("OUT PUT IS");
        Console.WriteLine("---------------------------------------------");
        Console.WriteLine("\nEnter Employee Number    : "+eno );
        Console.WriteLine("\nEnter The Employee Name  : "+ename );
        Console.WriteLine("\nEnter The Employee Ph. No: "+ph_no );

    }

}

public class big
{
    public static void Main()
    {

        emp obj= new emp();

        obj.get_data();
        obj.put_data();
    }

}

Recommended Answers

All 3 Replies

You have several options here :
If eno is an int then:
eno = Convert.ToInt32(Console.ReadLine());
or
eno = int.Parse(Console.ReadLine());
or
bool succes = int.TryParse(Console.ReadLine(), out eno);

@ddanbe

thank you so much.

whould u pls tell me which web site should i prefer for

" learning of c#"

You have several options here :
If eno is an int then:
eno = Convert.ToInt32(Console.ReadLine());
or
eno = int.Parse(Console.ReadLine());
or
bool succes = int.TryParse(Console.ReadLine(), out eno);

There are several, but they tend to be focused on older versions. Just Google!
This one is rather good : http://www.functionx.com/csharp/index.htm
I recommend to download Visual Studio Express 2008 C#.(free!) VS has a starting page with links to videos and other learning info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.