
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Check if an array object is equal to another array object in C#
To check if an array object is equal to another array object, the code is as follows −
Example
using System; public class Demo { public static void Main(){ String[] strArr1 = new String[3] { "John", "Jacob", "Tim"}; String[] strArr2 = new String[3] { "Tom","Brad","Bradley"}; Console.WriteLine("First String array..."); foreach(string val in strArr1){ Console.WriteLine(val); } Console.WriteLine("Second String array..."); foreach(string val in strArr2){ Console.WriteLine(val); } Console.WriteLine("Are both the array objects equal? = "+strArr1.Equals(strArr2)); } }
Output
This will produce the following output −
First String array... John Jacob Tim Second String array... Tom Brad Bradley Are both the array objects equal? = False
Example
Let us see another example −
using System; public class Demo { public static void Main(){ int[] arr1 = new int[5] { 10, 20, 30, 40, 50}; int[] arr2 = new int[5] { 25, 25, 40, 55, 70}; Console.WriteLine("First integer array..."); foreach(int val in arr1){ Console.WriteLine(val); } Console.WriteLine("Second integer array..."); foreach(int val in arr2){ Console.WriteLine(val); } arr1 = arr2; Console.WriteLine("Are both the array objects equal? = "+arr1.Equals(arr2)); } }
Output
This will produce the following output −
First integer array... 10 20 30 40 50 Second integer array... 25 25 40 55 70 Are both the array objects equal? = True
- Related Articles
- How do we check if an object is an array in Javascript?
- Determining If an Object Is an Array in Java
- How do I check if an array includes an object in JavaScript?
- How to check if an Image object intersects with another object using FabricJS?
- Check if object contains all keys in JavaScript array
- Fabric.js – How to check if an Image object is fully contained within the area of another object?
- FabricJS – Check if a Polygon Object is Fully Contained within Another Object?
- FabricJS – How to check if a Polygon Object Intersects with Another Object?
- How to check if Polyline object intersects with another object using FabricJS?
- How Check if object value exists not add a new object to array using JavaScript ?
- How to use array that include and check an object against a property of an object?
- Is there any way to check if there is a null value in an object or array in JavaScript?
- Sort object array based on another array of keys - JavaScript
- Convert object to an array in PHP.
- How to convert an object array to an integer array in Java?

Advertisements