In the sample below, I will show you how to convert a string to int inside a method
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace method001
{
class Program
{
static int calculDob(int a)
{
int year = 2008 - a; //calculation
return year; // the value being returned
}
static void Main(string[] args)
{
Console.WriteLine("How old are you? ");// asking for some data
int age = Convert.ToInt16(Console.ReadLine());// convert the entry to a int type and assign the value to the age variable
Console.WriteLine("You were born in: {0}",calculDob(age));
}
}
}
Visit:
Makai Studio
Currently rated 5.0 by 1 people
- Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5