Donate

IsDBNull() Equivalent in C#

When working with DBNull values in VB.NET you can check if that object is of type DBNull using IsDBNull(object). So, to do this in C#, I have two options to do this. The first one is to get the type of that object and compare it with typeof(System.DBNull).
Code
1
2
3
4
5
var attribute = element.getAttribute("data-mixvids");
if(attribute.GetType() != typeof(System.DBNull)) 
{
      lstElementVids.Add(element.getAttribute("data-mixvids"));
}

The other one is presented in MSDN docs using DBNull.Value.Equals(object) which returns true.
Code
1
2
3
4
5
var attribute = element.getAttribute("data-mixvids");
if(!System.DBNull.Value.Equals(attribute))
{
     lstElementVids.Add(element.getAttribute("data-mixvids"));
}

Reference: MSDN Convert.IsDBNull Method (Object)

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid