Please I have an array which filled with Number of elements, I want if specific Radiobutton is checked, specific elements removed from this array.... thank you
Asked
Active
Viewed 128 times
-1
-
LINQ Except them – Caius Jard Aug 29 '21 at 08:23
-
Please share some code you have already tried to write. – Qwertyluk Aug 29 '21 at 08:38
-
@Qwertyluk , I don't know the code of this process – Ahmed Yehia Aug 29 '21 at 08:51
-
Can you type the code >>>>> @CaiusJard – Ahmed Yehia Aug 29 '21 at 08:52
-
https://stackoverflow.com/questions/457453/remove-element-of-a-regular-array – Betsq9 Aug 29 '21 at 09:46
2 Answers
1
I am not sure if I fully understand what you mean, if you mean to delete specific element information after check radiobutton, I wrote a similar example.
If I misunderstood what you mean, please point it out and let me know.
The code of xaml is as follows:
<Grid>
<TextBlock x:Name="textbox_1" HorizontalAlignment="Left" Margin="158,59,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="92" Width="447" Background="#FFC9AD62"/>
<Button x:Name="button_1" Content="Original array" HorizontalAlignment="Left" Margin="158,173,0,0" VerticalAlignment="Top" Width="75" Click="Button_1_Click"/>
<RadioButton x:Name="RadioButton_1" Content="Delete less than 10" HorizontalAlignment="Left" Margin="273,176,0,0" VerticalAlignment="Top" Checked="RadioButton_1_Checked"/>
<RadioButton x:Name="RarioButton_2" Content="Delete more than 80" HorizontalAlignment="Left" Margin="414,176,0,0" VerticalAlignment="Top" Checked="RarioButton_2_Checked"/>
</Grid>
The code of xaml.cs is as follows:
using System;
using System.Linq;
using System.Windows;
namespace demo830 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void Button_1_Click(object sender, RoutedEventArgs e) {
//Generate 100 random integers between 1 and 99 and fill the array
//Array type is String array, size is 100
string[] a = new string[100];
Random r = new Random();
for (int i = 0; i < a.Length; i++) {
a[i] = r.Next(1, 100).ToString();
}
//Invoke display function
ViewArry(a);
}
//Display function
private void ViewArry(string[] b) {
this.textbox_1.Text="";//Initialize text before calling the output function
foreach (var i in b) {
this.textbox_1.Text = this.textbox_1.Text + i + " " ;
}
}
private void RadioButton_1_Checked(object sender, RoutedEventArgs e) {
string[] tmp = textbox_1.Text.Split(' ');//Here is "" as the demarcation
//Delete the element at the specified position of tmp
string[] c = tmp.Where(s => tmp.ToList().IndexOf(s) != tmp.Length-1).ToArray();
//Delete values less than 10
for (var i = c.Length - 1; i > -1; i--) {
if (c[i] != null) {
var item = Convert.ToInt32(c[i]);//Convert string to int
if (item < 10) {
//Delete the element at the specified position of c
string[] d = c.Where(s => c.ToList().IndexOf(s) != i).ToArray();
c = d;
}
}
}
ViewArry(c);
}
private void RarioButton_2_Checked(object sender, RoutedEventArgs e) {
string[] tmp = textbox_1.Text.Split(' ');//Here is "" as the demarcation
//Delete more than one blank data
string[] c = tmp.Where(s => tmp.ToList().IndexOf(s) != tmp.Length - 1).ToArray();
//Delete values greater than 80
for (var i = c.Length - 1; i > -1; i--) {
if (c[i] != null) {
var item = Convert.ToInt32(c[i]);
if (item > 80) {
string[] d = c.Where(s => c.ToList().IndexOf(s) != i).ToArray();
c = d;
}
}
}
//invoke the output function
ViewArry(c);
}
}
}
The running effect of my demo is as follows:

Jiale Xue - MSFT
- 3,560
- 1
- 6
- 21
-1
Please find the below-mentioned code
List<string> lstString = new List<string>
{
new string("ABC"),
new string("BCD"),
new string("CDE"),
new string("DEF"),
};
List<string> lstString1 = new List<string>
{
new string("AAA"),
new string("BCD"),
new string("ACD"),
new string("DEF"),
};
lstString.RemoveAll(x=> lstString1.Contains(x));