PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, December 21, 2022

[FIXED] What does "null!" default value of property mean?

 December 21, 2022     c#, operators, properties, syntax     No comments   

Issue

I have seen this below code in somewhere. There is a TodoItems property in the TodoContext class and it has a default value of "null!". I know this is a default value set for intended property but what does the exclamation mark(!) do at the end of the "null" value?

public class TodoContext : DbContext
{
    public TodoContext(DbContextOptions<TodoContext> options)
        : base(options)
    {
    }

    public DbSet<TodoItem> TodoItems { get; set; } = null!;
}

Solution

null! basically means null but the ! symbol suppresses the warning since your intentions are that it will be changed in a constructor or other places.



Answered By - misticos
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing