online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
using System; using System.Collections.Generic; using System.Linq; // A common base class public class MyBase { public int Id {get; set;} = 0; } public class MyDerived : MyBase { } public class MyParallelDerived : MyBase { } class Program { static void Main() { var l = new List<MyBase>(); for (int i = 0; i < 40; i++){ switch (i%4){ case 1: l.Add(new MyDerived(){Id = i}); break; case 2: l.Add(new MyParallelDerived(){Id = i}); break; case 3: l.Add(null); break; case 0: default: l.Add(new MyBase(){Id = i}); break; } } Console.WriteLine("Full List " + l.Count()); Console.WriteLine("OfType<MyBase> " + l.OfType<MyDerived>().Count()); Console.WriteLine("OfType<MyDerived> " + l.OfType<MyDerived>().Count()); Console.WriteLine("OfType<MyParallelDerived> " + l.OfType<MyParallelDerived>().Count()); Console.WriteLine("Select(s => s as MyBase) " + l.Select(s => s as MyBase).Count()); Console.WriteLine("Where(s => s is MyBase) " + l.Where(s => s is MyBase).Count()); try { Console.WriteLine("Cast<MyBase>() " + l.Cast<MyBase>().Count()); } catch (Exception ex){ Console.WriteLine("Cast<MyBase>() produced error " + ex.Message); } Console.WriteLine("Select(s => s as MyDerived) " + l.Select(s => s as MyDerived).Count()); Console.WriteLine("Where(s => s is MyDerived) " + l.Where(s => s is MyDerived).Count()); try { Console.WriteLine("Cast<MyDerived>() " + l.Cast<MyDerived>().Count()); } catch (Exception ex){ Console.WriteLine("Cast<MyDerived>() produced error " + ex.Message); } } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue