I'm learning C# so I'm converting some of my C++ projects to C# to learn the synatical differences. One thing I'm working on is the APCS Marine Biology Case Study Part I - eventually I will do part II but there are some fundamental C# things I'm failing to grasp, and I need help.
Console.read() reads in a stream of characters
Console.readline() reads in a string;
So now the question is, how do I read in integers?
Case in point:
using System;
class Demo
{
public static void Main()
{
int tankSize;
int stepsPerSim;
int step;
Console.Write("Tank size? ");
Size = Console.Read();
Console.WriteLine("tankSize = {0}", tankSize);
Console.Write("Steps per simulation? ");
stepsPerSim = Console.Read();
Console.WriteLine("stepsPerSim = {0}", stepsPerSim);
AquaFish fish = new AquaFish(tankSize);
for (step = 0; step < stepsPerSim; step++)
fish.Swim();
Console.WriteLine("Bump count = {0}", fish.BumpCount());
}
}
Appearantly, inputting '10' or some other integer comes out as a character, and myTankSize ends up being around 50, and I don't know why.
Can anyone explain?
BTW - is there a way for me to declare Main() just as void outside a class, as opposed to having to create a class and declaring it as public static void?
Console.read() reads in a stream of characters
Console.readline() reads in a string;
So now the question is, how do I read in integers?
Case in point:
using System;
class Demo
{
public static void Main()
{
int tankSize;
int stepsPerSim;
int step;
Console.Write("Tank size? ");
Size = Console.Read();
Console.WriteLine("tankSize = {0}", tankSize);
Console.Write("Steps per simulation? ");
stepsPerSim = Console.Read();
Console.WriteLine("stepsPerSim = {0}", stepsPerSim);
AquaFish fish = new AquaFish(tankSize);
for (step = 0; step < stepsPerSim; step++)
fish.Swim();
Console.WriteLine("Bump count = {0}", fish.BumpCount());
}
}
Appearantly, inputting '10' or some other integer comes out as a character, and myTankSize ends up being around 50, and I don't know why.
Can anyone explain?
BTW - is there a way for me to declare Main() just as void outside a class, as opposed to having to create a class and declaring it as public static void?