C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,198 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All,
I want to remove 3 digit where 2 of 3 substring are same and put in listbox2.
Expected result in listbox2 ( 324, 471, 341 )
here some code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DigitRemove
{
public partial class Form1 : Form
{
List<int> listDigithDuplicates = new List<int>() { 101, 221, 324, 471, 114, 233, 341, 443 };
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (var Val in listDigithDuplicates)
{
listBox1.Items.Add(Val);
}
}
private void button1_Click(object sender, EventArgs e)
{
listBox2.Items.Add();
}
}
}
Try one of solutions:
listBox2.Items.AddRange( listDigithDuplicates.Select( n => n.ToString( ) ).Where( n => n.Distinct( ).Count( ) == 3 ).ToArray( ) );