ADVERTISEMENT
ADVERTISEMENT

C# program to print the list of non-generic collections using LINQ

Here, we are going to learn how to print the list of non-generic collections using LINQ in C#?
Submitted by Nidhi, on August 20, 2020

In this program, we will print the list of non-generic collections using LINQ with the help of the IEnumerable interface in C#.

Program:

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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.