| |

VerySource

 Forgot password?
 Register
Search
Author: 393736105

How to represent 0 of short type?

[Copy link]

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-7-25 18:00:01
| Show all posts
The landlord knows packing, don't you know unpacking?
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

 Author| Post time: 2020-7-25 18:15:01
| Show all posts
When it is running, I don't know what type of box to disassemble.
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

 Author| Post time: 2020-7-25 18:45:02
| Show all posts
Because this value may be one of int, short, or long, I have no other way except to compare them one by one.
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-7-25 19:30:02
| Show all posts
short a = 0;
object obj = a;
short aa = (short)obj;
bool b = (aa==0);
System.Console.WriteLine(b);
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

 Author| Post time: 2020-7-25 20:00:02
| Show all posts
Dude despise me too much, if it's that simple, I won't ask:

short aa = (short)obj;
How do I know to use shot to cast instead of long...
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-7-26 01:30:01
| Show all posts
//Now there is no other way except to compare one by one
correct

if (obj is short)
{
    short aa = (short)obj;
}
if (obj is int)
{
    int aa = (int)obj;
}
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

 Author| Post time: 2020-7-26 11:45:01
| Show all posts
It seems that it can only be written like this. I looked at the integer table which has the following types:
sbyte byte char short ushort int uint long ulong
To know the zero value they correspond to, you can only write it in the following way:

if (object.Equals(obj, (sbyte)0) || object.Equals(obj, (byte)0) || object.Equals(obj, (char)0) || object.Equals(obj, (short) 0) || object.Equals(obj, (ushort)0) || object.Equals(obj, (int)0) || object.Equals(obj, (uint)0) || object.Equals(obj, ( long)0) || object.Equals(obj, (ulong)0))
{
     System.Console.WriteLine("zero value");
}
else
{
    System.Console.WriteLine("Non-zero value");
}
Reply

Use magic Report

0

Threads

8

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-7-26 12:00:01
| Show all posts
//Now there is no other way except to compare one by one
correct


Isn't it enough to just use Convert? Convert.ToDouble or Convert.ToInt64


In addition, short j = i + 2; the reason for this compilation error is thatcqgangsaid that the short type cannot participate in the operation, that is, short + short will become int.

    short i, j;
    i = j = 1;
   
    short k = i + j;

This program cannot be compiled either...
Reply

Use magic Report

0

Threads

8

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-7-26 12:15:01
| Show all posts
If you are sure that ulong will not appear, just use Convert.ToInt64...
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

 Author| Post time: 2020-7-26 14:45:01
| Show all posts
It’s also a way to use one type of mandatory representation, but it may be "distorted" if you turn around.
This is why I did not adopt this method.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list