Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,914 questions

51,847 answers

573 users

How to check if two List objects are equal in C#

2 Answers

0 votes
using System;
using System.Collections.Generic; 
                       
public class Program
{
    public static void Main()
    {
        List<string> list1 = new List<string>(); 
   
        list1.Add("c#"); 
        list1.Add("c++"); 
        list1.Add("c"); 
 
        List<string> list2 = new List<string>(); 
   
        list2.Add("c#"); 
        list2.Add("c++"); 
        list2.Add("c"); 
         
        Console.WriteLine(list1.Equals(list2)); 
   
        List<string> list3 = new List<string>(); 
        list3 = list1; 
        Console.WriteLine(list3.Equals(list1)); 
        
        Console.WriteLine(list3.Equals(list2)); 
    }
}
   
 
   
/*
run:
   
False
True
False
   
*/

 



answered May 10, 2020 by avibootz
edited Apr 15, 2024 by avibootz
0 votes
using System;
using System.Linq;
using System.Collections.Generic; 
                       
public class Program
{
    public static void Main()
    {
        List<string> list1 = new List<string>(); 
   
        list1.Add("c#"); 
        list1.Add("c++"); 
        list1.Add("c"); 
 
        List<string> list2 = new List<string>(); 
   
        list2.Add("c#"); 
        list2.Add("c++"); 
        list2.Add("c"); 
         
        Console.WriteLine(list1.SequenceEqual(list2)); 
        
        bool isEqual = list1.All(list2.Contains) && list2.All(list1.Contains);
        Console.WriteLine(isEqual);  
        
    }
}
   
 
   
/*
run:
   
True
True
   
*/

 



answered Apr 15, 2024 by avibootz

Related questions

1 answer 152 views
1 answer 77 views
1 answer 99 views
1 answer 146 views
146 views asked May 6, 2020 by avibootz
1 answer 131 views
1 answer 94 views
...