How to check if an array is empty in C#
In this post we will give you information about How to check if an array is empty in C#. Hear we will give you detail about How to check if an array is empty in C#And how to use it also give you demo for it if it is necessary.
we are going to learn about how to check if an array is empty or not in C#.
Checking the empty array
To check if an given array is empty or not, we can use the built-in Array.Length property in C#.
Here is an example:
using System;class Check { static void Main() { int[] myArr = new int[] {}; if (myArr.Length == 0) { Console.WriteLine("array is empty"); }else{ Console.WriteLine("array is not empty"); } }}Alternatively, we can also use the Array.Length property to check if a array is null or empty in C#.
using System;class Check { static void Main() { int[] myArr = new int[] {}; if (myArr == null || myArr.Length == 0) { Console.WriteLine("array is empty"); }else{ Console.WriteLine("array is not empty"); } }}Note: The string.Length property returns the total number of elements in a given Array.
Hope this code and post will helped you for implement How to check if an array is empty in C#. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
