G
garyusenet
I'm trying to investigate the maximum size of different variable types.
I'm using INT as my starting variable for exploration. I know that the
maximum number that the int variable can take is: 65,535. But i'm
trying to write a program to test this, assuming I didn't know this
number in advance. I came up with the following but have two questions.
Maybe someone can help?
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int j = 0;
double i = 0;
for (i = 0; i < 9999999999999999999; i++)
{
j = (int)i;
Console.WriteLine(j.ToString());
///on error console.write(there was an error... this
was the error code)
}
}
}
}
q.1.
I want to have an idea of what is going on in my program. As you can
see, in my for loop I am writing the value of j to the screen on a new
line every time it is incremented. This is too slow. It seems to be
taking forever to scroll through the digits. My question is, is there a
way that I can display the value of j every, say, 10 thousand
increments?
q.2.
is there a way I can time how long the loop takes to complete, and at
the end of the loop display this time?
q.3
I'd like to output an error message to the screen when the variable
crashes because it's too small to hold the number being allocated to
it. How do i do this?
Thankyou,
Gary.
I'm using INT as my starting variable for exploration. I know that the
maximum number that the int variable can take is: 65,535. But i'm
trying to write a program to test this, assuming I didn't know this
number in advance. I came up with the following but have two questions.
Maybe someone can help?
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int j = 0;
double i = 0;
for (i = 0; i < 9999999999999999999; i++)
{
j = (int)i;
Console.WriteLine(j.ToString());
///on error console.write(there was an error... this
was the error code)
}
}
}
}
q.1.
I want to have an idea of what is going on in my program. As you can
see, in my for loop I am writing the value of j to the screen on a new
line every time it is incremented. This is too slow. It seems to be
taking forever to scroll through the digits. My question is, is there a
way that I can display the value of j every, say, 10 thousand
increments?
q.2.
is there a way I can time how long the loop takes to complete, and at
the end of the loop display this time?
q.3
I'd like to output an error message to the screen when the variable
crashes because it's too small to hold the number being allocated to
it. How do i do this?
Thankyou,
Gary.