same substring.

MiPakTeh 1,476 Reputation points
2022-10-09T01:48:14.007+00:00

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();  
        }  
    }  
}  
  
C#
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.
10,387 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 113K Reputation points
    2022-10-09T08:08:27.42+00:00

    Try one of solutions:

    listBox2.Items.AddRange( listDigithDuplicates.Select( n => n.ToString( ) ).Where( n => n.Distinct( ).Count( ) == 3 ).ToArray( ) );  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful