Program in C# to find the presence of reverse of an element in a collection.

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 197
Suppose we have a colleciton as {78,92,44,63,71,97} and an element 29. We need to find if the reverse of 29 i.e. 92 is present in the collection. The below program will do so

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{

var intCollection = new List<int>() { 78, 92, 44, 63, 71, 97 };
var element = 29;
var reverseElement = Convert.ToInt32(string.Join("", element.ToString().Reverse()));
Console.Write(intCollection.IndexOf(reverseElement) != -1 ? "Element found in the collection" : "Element not found in the collection");
Console.ReadKey();

}
}
}

Result
-------
Element found in the collection

Comments or Responses

Login to post response