switch新的用法

 

 

 

 

List<Object> list = new List<object>();
            list.Add(0);
            list.Add(new List<int>()
            {
                2, 4, 6
            });
            list.Add(null);List<Object> list = new List<object>();
            list.Add(0);
            list.Add(new List<int>()
            {
                2, 4, 6
            });
            list.Add(null);
            list.Add(11);
            foreach (var item in list)
            {
                switch (item)
                {
                    case 0:
                      
                        break;

                    case IEnumerable<int> test:

                        break;

                    case int n when n > 2:

                        break;
                    case null:

                        break;
                    default:
                        break;
                }

            }
            list.Add(11);
            foreach (var item in list)
            {
                switch (item)
                {
                    case 0:
                      
                        break;

                    case IEnumerable<int> test:

                        break;

                    case int n when n > 2:

                        break;
                    case null:

                        break;
                    default:
                        break;
                }

            }

  

posted @ 2021-12-18 10:37  艾特-天空之海  阅读(20)  评论(0编辑  收藏  举报