I want to a C# console application code... My problem is... i want take input from keybord a ID like 10510023.. and the 1st 2 digit of this code indicate the year of a student like if ID is 10510023 the year is 2010 or if it is 13510023 the year is 2013.. like same... 3rd digit indicate his or her semester, 4th digit for her branch.. and next digit is serial.... please someone help me...

What do you have so far?

Since you're coding a console app, use console.readline and your input will be a string. from there simply validate that each character is a digit, and a for loop can easily parse the string into the values you want.

here string is using to store ID

string str;
str = Console.ReadLine();
Console.Write("year is=20");
for (int i = 0; i < 2; i++)
Console.WriteLine("semester is=" + str[2]);
Console.WriteLine("Branch  is=" + str[3]);
Console.Write("serial is=");
for (int i = 4; i < str.Length; i++)

hope this helps you to solve the issue . . .

thanks for reply rishif2.. but i need something more ... if str[2] is 3 i want to show semester is fall if it is 4 i want show summer then if it is 5 i want to show spring... and also want to do the same thing with the branch for different digit i want to show the name of different branch, pls help me..

You could use Enums for instance

enum semester
    Fall = 4,
    Summer = 5,
    Spring = 6


Console.WriteLine("semester is=" + Enum.GetName(typeof(semester), int.Parse(str[2])));

You can do the same with the branches.



i think that int.Parse will take string argument and so it will not work since str[2] is char

so , to execute this , we need to convert it to string :-

Console.WriteLine("semester is=" + Enum.GetName(typeof(semester), int.Parse(str[2].ToString())));