Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

mukundkallapur

@mukundkallapur
About
Posts
2
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to handle Enter key...
    M mukundkallapur

    Please go through...

    class Test
    {

    Console.WriteLine("1:Add\n2:Sub\n3:Mult:\n4:Div");
    Console.WriteLine();
    Console.WriteLine("Press 9 to Exit or Enter to Continue ");

    string s=Console.ReadLine();

    ....

    }

    My query is that when I enter the "ENTER" key, it does go ahead but it also does the same for the other keys except 9, for which it exits from the Program. Hope so I will get a solution

    C# database tutorial

  • EXCEPTION HANDLING
    M mukundkallapur

    Kindly check the below program.

    /* Brief Decsription : This program checks whether the entered chatacter is a numeral or no.
    I have used the IsDigit Method. The issue here is that, the input from keyboard is a string,
    whereas the IsDigit method needs a character. Hence I have converted the string input to a character.

    Now, when I enter any number from 0 to 9, it perfoms the functionality of addition and also if I
    enter any character it hroes an Exception. But if I enter any 2 digit number, then also it throws an
    Exception, which is system generated.

    This is because of that converison to character.

    Kindly provide a solution wherein I can enter numerals greater than 9 without error */

    using System;

    namespsace TestException3
    {
    Class program
    {
    static void Main(string args[])
    {
    try
    {
    string s1,s2,ans;
    char type,type1;

    Console.WriteLine("please enter the variables : ");
    s1=Console.ReadLine();
    s2=Console.ReadLine();

    type=Convert.ToChar(s1);
    type1=Convert.ToChar(s2);

    if(!(char.IsDigit(type)) || !(char.IsDigit(type1)))
    {
    throw new Exception("Please Enter numbers only");
    }
    else
    {
    ans=Convert.ToString(Convert.ToInt32(s1)+Convert.ToInt32(s2));
    Console.WriteLine(Answer : {0}",ans);
    Console.ReadLine();
    }
    catch(Exception e)
    {
    Console.WriteLine("Message : {0}", e.Message);
    Console.ReadLine();
    }
    }
    }
    }

    C# help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups