nullable Questions
11
I can see that @Nullable and @Nonnull annotations could be helpful in preventing NullPointerExceptions but they do not propagate very far.
The effectiveness of these annotations drop off complete...
Chatelain asked 20/11, 2012 at 23:48
2
Solved
I just discovered this interesting issue:
int done = 50;
int? total = 100;
var perc = done * 100 / total; // No problem
// Error: Argument 2: cannot convert from 'int?' to 'byte'
// Argument 1 is...
Modesta asked 17/4, 2023 at 16:5
3
My code is below, working fine in .NET Core 3.1:
// dto is search criteria passing from outside
var query = from p in dbContext.Products.Where(p => dto.Ids.Contains(p.Id))
from c in dbContext.C...
5
Solved
From my controller I have passed value module to view
public ActionResult Details(long id, string owner)
{
var module = _ownedModuleRepository.GetModuleDetails(id, owner);
return View(module)...
Nigercongo asked 29/7, 2013 at 7:59
4
Solved
I like to use pattern-matching on a nullable int i.e. int?:
int t = 42;
object tobj = t;
if (tobj is int? i)
{
System.Console.WriteLine($"It is a nullable int of value {i}");
}
However, this r...
Misology asked 19/1, 2018 at 14:9
4
I've a method that generates list of class type from data of data reader.
if (datareader != null && datareader .HasRows)
{
Dictionary<string, PropertyInfo> pDict= GetPropertyDictiona...
Nikaniki asked 13/6, 2018 at 16:38
4
Solved
I want to convert a web form to a model in Java.
In C# I can write this:
<input name="id" value="" type="text"/>
public class Test
{
public int? Id{get;set;}
}
The id can be null.
But...
1
I am using OpenAPI 3.0 to design and implement a simple API to allow basic CRUD operations on database entities.
Let's assume an entity Pet with some client-given properties (name & age) and so...
5
Solved
I am starting to learn nullable types and ran into following behavior.
While trying nullable int, i see comparison operator gives me unexpected result. For example, In my code below, The output i ...
2
Solved
When I write this statement:
var x = new ClassName();
x is implicitly typed as a ClassName?. That is, since ClassName is a reference type, implicit assignments using var automatically define as nul...
Collotype asked 10/1, 2023 at 22:23
20
Solved
In C#, say that you want to pull a value off of PropertyC in this example and ObjectA, PropertyA and PropertyB can all be null.
ObjectA.PropertyA.PropertyB.PropertyC
How can I get PropertyC safely...
Aggappera asked 12/8, 2010 at 13:40
9
Solved
Surprisingly the following code fails the Assert:
int? wtf = 0;
Assert.IsType<Nullable<int>>(wtf);
So just out curiosity, how can you determine if a given instance is a Nullable<>...
Bhatt asked 17/5, 2011 at 5:58
10
Solved
I have been repeatedly asked the following questions in many interviews.... But still can't explain them with a simple example...
What are nullable types in c#?
When should one use nullable types...
5
Solved
I tried to do something like the following:
val a: Int? = 1
val b: Int? = 1
a?.plus(b)
but it doesn't compile cause plus expects an Int.
I also tried to create a biLet function:
fun <V1, ...
12
I created a migration with unsigned user_id. How can I edit user_id in a new migration to also make it nullable()?
Schema::create('throttle', function(Blueprint $table)
{
$table->increments('i...
Dallapiccola asked 25/6, 2014 at 23:3
4
Solved
In Swift, it's rare but possible to end up with a value of a non-optional type that has a nil value. As explained in answers to this question, this can be caused by bad Objective-C code bridged to ...
Amaris asked 30/10, 2017 at 15:45
7
Solved
I need to return values, and when someone asks for a value, tell them one of three things:
Here is the value
There is no value
We have no information on this value (unknown)
case 2 is subtly d...
Pneumatometer asked 15/11, 2009 at 16:47
0
I'm writing up a generic method that needs to internally use a Dictionary keyed by the generic parameter.
I don't want to impose any constraint on the generic parameter itself, in particular no not...
Syphon asked 23/11, 2022 at 10:5
8
I've got a prop on a ReactJS Component that's either null or an Immutable Map.
At the bottom of my widget if I write:
MyComponent.propTypes = {
myMap: React.PropTypes.instanceOf(Immutable.Map)
...
Judaism asked 21/11, 2016 at 21:23
6
Solved
C# 8.0 introduces nullable reference types. Here's a simple class with a nullable property:
public class Foo
{
public String? Bar { get; set; }
}
Is there a way to check a class property uses a...
Bursarial asked 18/10, 2019 at 15:31
4
Solved
I have a class which contains a nullable strings, I want to make a check to see whether they stay null or somebody has set them.
simliar to strings, the class contains integers which are nullable...
4
Solved
I am new to Kotlin. I am following along a tutorial where the GUI portion involves this code snippet:
sampleList.addMouseListener(object: MouseAdapter() {
override fun mouseClicked(mouseEvent: M...
8
Solved
Often, I can see a code constructs like following:
if(a == null || b == null || c == null){
//...
}
I wonder if there is any widely used library (Google, Apache, etc.) to check against nullity ...
6
Solved
If have this in the setter of a property:
decimal? temp = value as decimal?;
value = "90"
But after the cast, temp is null...
What is the proper way to do this cast?
3
Solved
I have an Asp.net Core 6 Web Api project.
I am trying to protect against NullReferenceException.
I have added the following setting to all projects:
<Nullable>enable</Nullable>
I have ...
Springer asked 30/6, 2022 at 9:47
© 2022 - 2024 — McMap. All rights reserved.