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.

Recommended Answers

All 3 Replies

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.

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)

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

int t = 10;
int i = checked(-1234567891*t);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.