0

i am confused about "Checked" in C#. I know it use for overflow checking. Can we use it for undeflow ? Or there is some thing else which an be use for underflow.

2
Contributors
3
Replies
8
Views
3 Years
Discussion Span
Last Post by ddanbe
1

Hi coolsdudes1992, welcome at DaniWeb!
I'm confused about your question.
Could you give an example, where "Checked" is used for overflow checking?
O, and this should be posted in the C# departement.

Edited by ddanbe: add

0

Thanks for your reply.

Code :

long l=new long();

        int i=new int();
        l = long.Parse(Console.ReadLine());
        try
        {

            i =checked((int) l);
        }
        catch{
        Console.WriteLine("Heyt :S ");
        }
           Console.WriteLine(i);
        Console.ReadLine();

yeah sorry for this, it should be on C#(actually i am new in daniweb)

1

Overflow, also means underflow in this case.
This will generate an overflow exeption:

int t = 10;
int i = checked(-1234567891*t);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.