Home »
.Net »
C# Programs
C# - Print the list of non-generic collections using LINQ
Learn, how to print the list of non-generic collections using LINQ in C#?
By Nidhi Last updated : April 01, 2023
Printing list of non-generic collections
In this program, we will print the list of non-generic collections using LINQ with the help of the IEnumerable interface in C#.
C# program to print the list of non-generic collections using LINQ
The source code to print a list of non-generic collections using LINQ in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//Program to print the list of non-generic
//collections using LINQ in C#.
using System;
using System.IO;
using System.Linq;
using System.Collections;
class IEnumerableDemo {
public static void Main(string[] args) {
var Type = typeof (IEnumerable);
var IEnumType = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x =>
x.GetTypes()).Where(x => Type.IsAssignableFrom(x));
foreach(var type in IEnumType) {
Console.WriteLine("##########" + type.FullName + "#########");
}
}
}
Output
##########System.Diagnostics.ProcessThreadCollection#########
##########System.ComponentModel.WeakHashtable#########
##########System.Collections.Concurrent.BlockingCollection`1+<GetConsumingEnumerable>d__0#########
##########System.Collections.Generic.SortedSet`1+<Reverse>d__12#########
##########System.Diagnostics.ListenerElementsCollection#########
##########System.Diagnostics.SharedListenerElementsCollection#########
##########System.Diagnostics.SourceElementsCollection#########
##########System.Collections.Specialized.ListDictionary+NodeKeyValueCollection#########
##########System.Collections.Specialized.OrderedDictionary+OrderedDictionaryKeyV
alueCollection#########
##########System.Collections.Specialized.StringDictionaryWithComparer#########
##########System.Net.ProxyScriptChain#########
##########System.Net.DirectProxy#########
##########System.Net.StaticProxy#########
##########System.Configuration.ConfigXmlAttribute#########
##########System.Configuration.ConfigXmlCDataSection#########
##########System.Configuration.ConfigXmlComment#########
##########System.Configuration.ConfigXmlElement#########
##########System.Configuration.ConfigXmlSignificantWhitespace#########
##########System.Configuration.ConfigXmlText#########
##########System.Configuration.ConfigXmlWhitespace#########
##########System.Configuration.ReadOnlyNameValueCollection#########
Press any key to continue . . .
Explanation
In the above program, we created the IEnumerableDemo class that contains the Main() method. Here we get the list of non-generic collections using LINQ than print them using the foreach loop on the console screen.
C# LINQ Programs »