C# Program to Print the List of Non-Generic Collections Using LINQ Last Updated : 01 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The non-Generic collection is defined in System.Collections namespace. It is a general-purpose data structure that works on object references, so it can handle any type of object, but not in a safe-type manner. Non-generic collections are defined by the set of interfaces and classes. We can get all types that implement an interface by using AppDomain along with CurrentDomain. These two domains will get the list of collections. Along with that, we will use IEnumerable. IEnumerable is an interface in C# which is used to define one method that only allows readonly access to a collection and then a collection that implements this interface can be used with a for-each statement. This interface contains the System.Collections.Generic namespace. IEnumerable interface is a generic interface that allows looping over generic or non-generic lists. Syntax: public IEnumerator method() { // Statements } Return: This method returns an enumerator that iterates through the collection. Example: C# // C# program to illustrate how to display the // list of non-generic collections using LINQ using System; using System.IO; using System.Linq; using System.Collections; class GFG{ public static void Main(string[] args) { // Get the type of IEnumerable var result = typeof(IEnumerable); // Get the domain var nonGenCollection = AppDomain.CurrentDomain.GetAssemblies().SelectMany( x => x.GetTypes()).Where(x => result.IsAssignableFrom(x)); // Display all the types using for loop foreach (var detail in nonGenCollection) { Console.WriteLine("---> " + detail.FullName); } } } Explanation: In this example, we defined a "nonGenCollection" variable that will get all the IEnumTypes by using "AppDomain.CurrentDomain.GetAssemblies()" method. This method will get all the lists of non-generic collections. Then we have iterated a for each loop to display the full name of the collection Output: ---> Mono.Security.X509.X509CertificateCollection ---> Mono.Security.X509.X509ExtensionCollection ---> System.ArraySegment`1 ---> System.String ---> System.Array ---> System.Resources.IResourceReader ---> System.Resources.ResourceFallbackManager ---> System.Resources.ResourceReader ---> System.Resources.ResourceSet ---> System.Resources.RuntimeResourceSet ---> System.Reflection.TypeInfo+<GetDeclaredMethods>d__9 ---> System.Reflection.TypeInfo+<get_DeclaredNestedTypes>d__23 ---> System.Reflection.Assembly+<get_DefinedTypes>d__150 ---> System.Threading.ThreadPool+<EnumerateQueuedWorkItems>d__21 ---> System.Threading.Tasks.IProducerConsumerQueue`1 ---> System.Threading.Tasks.MultiProducerMultiConsumerQueue`1 ---> System.Threading.Tasks.SingleProducerSingleConsumerQueue`1 ---> System.Threading.Tasks.ThreadPoolTaskScheduler+<FilterTasksFromWorkItems>d__7 ---> System.IO.Iterator`1 ---> System.IO.FileSystemEnumerableIterator`1 ---> System.IO.DirectoryInfo+<CreateEnumerateDirectoriesIterator>d__39 ---> System.IO.DirectoryInfo+<CreateEnumerateFilesIterator>d__43 ---> System.IO.DirectoryInfo+<EnumerateFileSystemInfos>d__47 ---> System.IO.File+<ReadLines>d__58 ---> System.Runtime.Serialization.SurrogateHashtable ---> System.Runtime.Remoting.Channels.AggregateDictionary ---> System.Runtime.Remoting.Channels.BaseChannelObjectWithProperties ---> System.Runtime.Remoting.Channels.BaseChannelSinkWithProperties ---> System.Runtime.Remoting.Channels.BaseChannelWithProperties ---> System.Runtime.Remoting.Messaging.ConstructionCallDictionary ---> System.Runtime.Remoting.Messaging.MCMDictionary ---> System.Runtime.Remoting.Messaging.MethodCallMessageWrapper+DictionaryWrapper ---> System.Runtime.Remoting.Messaging.MessageDictionary ---> System.Runtime.Remoting.Messaging.MethodReturnDictionary ---> System.Runtime.Remoting.Messaging.MethodReturnMessageWrapper+DictionaryWrapper ---> System.Security.NamedPermissionSet ---> System.Security.PermissionSet ---> System.Security.Policy.ApplicationTrustCollection Press enter to continue ...... Comment More infoAdvertise with us Next Article C# Program to Find the List of Students whose Name Starts with 'S' using where() Method of List Collection using LINQ S sravankumar_171fa07058 Follow Improve Article Tags : C# CSharp LINQ CSharp-programs Similar Reads C# Program to Print the Numbers Greater Than 786 in an Integer Array using LINQ Language-Integrated Query (LINQ) is a uniform query syntax in C# to retrieve data from different sources. It eliminates the mismatch between programming languages and databases and also provides a single querying interface for different types of data sources. In this article, we will learn how to di 2 min read C# | Get a collection of values in the StringDictionary StringDictionary.Values property is used to get a collection of values in the StringDictionary. Syntax: public virtual System.Collections.ICollection Values { get; } Return Value: An ICollection that provides the values in the StringDictionary. Example 1: CSHARP // C# code to get a collection // of 2 min read C# Program to Find the List of Students whose Name Starts with 'S' using where() Method of List Collection using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 3 min read C# | Add an object to the end of Collection<T> Collection<T>.Add(T) method is used to add an object to the end of the Collection<T>. Syntax : public void Add (T item); Here, item is the object to be added to the end of the Collection<T>. The value can be null for reference types. Below given are some examples to understand the 2 min read C# Program to Find the List of Students whose Name Contains 4 Characters Using Where() Method of List Collection using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 2 min read C# | Adding the elements of the specified collection to the end of the List List<T>.AddRange(IEnumerable<T>) Method is used to add the elements of the specified collection to the end of the List<T>. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot. List class can accept null as a valid value for refer 3 min read Like