C#7.0 模式匹配与if语句

 1 using System;
 2                     
 3 public class Program
 4 {
 5     public static void Main()
 6     {
 7         object o ="3";
 8         int j = 4;
 9         
10         if(o is int i)
11         {
12             Console.WriteLine($"{i}x{j}={i*j}");
13         }
14         else
15         {
16             Console.WriteLine("o is not an int so it cannot muitiply!");
17         }
18     }
19 }

 

posted @ 2022-01-11 12:44  data_byte  阅读(48)  评论(0编辑  收藏  举报