Check, cast and assign object - CSharp Custom Type

CSharp examples for Custom Type:Box Unbox

Description

Check, cast and assign object

Demo Code

using System;/* w  w  w. j a  va 2  s .  co  m*/
using static System.Console;
using System.IO;
class Program
{
   static void Main(string[] args)
   {
      object o = 3;
      int j = 4;
      if (o is int i)
      {
         WriteLine($"{i} x {j} = {i * j}");
      }
      else
      {
         WriteLine("o is not an int so it cannot multiply!");
      }
   }
}

Result


Related Tutorials