Could be dumb question, but how can I pass null to method which takes long or int?
Example:
TestClass{ public void iTakeLong(long id); public void iTakeInt(int id); } now how can i pass null to both methos:
TestClass testClass = new TestClass(); testClass.iTakeLong(null); // Compilation error : expected long, got null testClass.iTakeInt(null); // Compilation error : expected int, got null Thoughts, suggestions?
Int? a=null; Nullable<int>a=null; Null value.
You can pass NULL as a function parameter only if the specific parameter is a pointer. The only practical way is with a pointer for a parameter. However, you can also use a void type for parameters, and then check for null, if not check and cast into ordinary or required type.
If you have declared the data type of Plate number as long, then obviously its initial value will be '0' and not 'null'. So, if you try to increment, it will run without any issues.
Assigning Null to Variables null can only be assigned to reference type, you cannot assign null to primitive variables e.g. int, double, float, or boolean.
The problem is that int and long are primitives. You can't pass null to a primitive value.
You can certainly use the wrapper classes Integer and Long instead of long and int in your method signature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With