本文整理汇总了C#中List.RemoveAll方法的典型用法代码示例。如果您正苦于以下问题:C# List.RemoveAll方法的具体用法?C# List.RemoveAll怎么用?C# List.RemoveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.RemoveAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMostCommonElementList
private static List<int> GetMostCommonElementList(List<int> intsList)
{
intsList.Sort();
List<int> listWithRemovedElements =new List<int>(intsList);
int listCount = intsList.Count;
int currentNumber = intsList[0];
int occurance = 1;
for (int i = 0; i <= listCount - 1; i++)
{
if (i == listCount - 1 && intsList[i] != intsList[i-1])
{
currentNumber = intsList[i];
listWithRemovedElements.RemoveAll(x => x == currentNumber);
}
else if (intsList[i] == intsList[i + 1])
{
occurance++;
}
else
{
if (occurance % 2 != 0)
{
currentNumber = intsList[i];
listWithRemovedElements.RemoveAll(x => x == currentNumber);
}
occurance = 1;
}
}
return listWithRemovedElements;
}
示例2: Parse
public override bool Parse(List<string> aAnswer)
{
if (!aAnswer.Contains(BASE_ERROR) && aAnswer.Contains("OK"))
{
aAnswer.RemoveAll(OKString);
aAnswer.RemoveAll(this.ReadParamsClone);
aAnswer.RemoveAll(String.IsNullOrEmpty);
if (aAnswer.Count == 1)
{
string[] zSplit = aAnswer[0].Split(new Char[] { ' ', ' ', ' ' });
if (zSplit.Count() == 3)
{
String zCleanSN = TrimValue(zSplit[2]);
SerialNumber = zCleanSN;
return true;
}
else
{
_logger.Debug("InCorrect Params Count: {0}", zSplit.Count());
return false;
}
}
else
return false;
} else
return false;
}
示例3: CorruptEntityAnimations_Func
private bool CorruptEntityAnimations_Func()
{
List<string> tocorrupt = new List<string>();
if (!LoadXMLAndModify("./entities2.xml", delegate (XmlDocument XML)
{
tocorrupt.AddRange(from XmlNode n in XML.LastChild.ChildNodes select n.Attributes["anm2path"].Value);
}))
{ return false; }
tocorrupt.RemoveAll(x => x.Length == 0);
tocorrupt.RemoveAll(x => x.Contains("Fireworks") == true);
if (!tocorrupt.Select(corruptfile => "./gfx/" + corruptfile)
.All(toopen => LoadXMLAndModify(toopen, delegate (XmlDocument XML)
{
AnimCont A = new AnimCont();
foreach (XmlNode frame in XML.GetElementsByTagName("Frame"))
{
CorruptFrame(frame, A);
}
})))
{ return false; }
List<string> itemfiles = Safe.GetFiles("./gfx/characters");
return itemfiles.All(file => LoadXMLAndModify(file, delegate (XmlDocument XML)
{
AnimCont A = new AnimCont();
foreach (XmlNode frame in XML.GetElementsByTagName("Frame"))
{
CorruptFrame(frame, A);
}
}));
}
示例4: PrepareProducts
private void PrepareProducts(List<Product> products)
{
products.RemoveAll(x => x.Name.Contains("*"));
var coupon = products.FirstOrDefault(x => x.Name.Contains("$"));
if (coupon != null)
{
for (var i = 0; i < coupon.Quantity; i++)
{
var bread = products.First(x => x.Name.Contains("хляб") && !x.Name.Contains("$") && x.Quantity > 0 && x.SellingPrice > coupon.SellingPrice * -1);
bread.Quantity--;
var breadWithCouponName = bread.Name + " с купон";
var breadWithCoupon = products.FirstOrDefault(x => x.Name == breadWithCouponName);
if (breadWithCoupon != null)
{
breadWithCoupon.Quantity++;
}
else
{
breadWithCoupon = new Product { Name = breadWithCouponName, SellingPrice = bread.SellingPrice - coupon.SellingPrice * -1, Quantity = 1 };
products.Add(breadWithCoupon);
}
}
products.RemoveAll(x => x.Quantity == 0);
products.RemoveAll(x => x.Name.Contains("$"));
}
}
示例5: Main
static void Main(string[] args)
{
Console.Write("Show all prime numbers from 1 to ");
int n = int.Parse(Console.ReadLine());
List<int> numbers = new List<int>();
numbers.Add(2); //adding 2 in the list
for (int i = 0; i < n - 2; i += 2) //so it can show numbers from 3 to N and excluding all even numbers
{
numbers.Add(i + 3);
}
int range = (int)(Math.Sqrt(n)); //check for divisors up to the square root of N
//first removing numbers divisible by 3, 5, 7, 11
numbers.RemoveAll(item => item % 3 == 0 && item != 3);
numbers.RemoveAll(item => item % 5 == 0 && item != 5);
numbers.RemoveAll(item => item % 7 == 0 && item != 7);
numbers.RemoveAll(item => item % 11 == 0 && item != 11);
//then checking the rest divisiors with the help of the range
for (int i = 13; i < range; i += 2)
{
numbers.RemoveAll(item => item % i == 0);
}
//printing numbers
Console.WriteLine("The prime numbers from 1 to N are: ");
Console.WriteLine(String.Join(", ", numbers));
}
示例6: BuildFolderList
protected void BuildFolderList() {
List<FileData> lstFolders = new List<FileData>();
string sRoot = Server.MapPath("~/");
string[] subdirs;
try {
subdirs = Directory.GetDirectories(sRoot);
} catch {
subdirs = null;
}
if (subdirs != null) {
foreach (string theDir in subdirs) {
string w = FileDataHelper.MakeWebFolderPath(theDir);
lstFolders.Add(new FileData { FileName = w, FolderPath = w, FileDate = DateTime.Now });
}
}
lstFolders.RemoveAll(f => f.FileName.ToLower().StartsWith(SiteData.AdminFolderPath));
lstFolders.RemoveAll(f => f.FileName.ToLower().StartsWith("/bin/"));
lstFolders.RemoveAll(f => f.FileName.ToLower().StartsWith("/obj/"));
lstFolders.RemoveAll(f => f.FileName.ToLower().StartsWith("/app_data/"));
ddlFolders.DataSource = lstFolders.OrderBy(f => f.FileName);
ddlFolders.DataBind();
}
示例7: Main
public static void Main (string[] args) {
var l = new List<string> {
"A", "A", "B", "C", "D"
};
PrintItems(l);
Console.WriteLine(l.RemoveAll((s) => s == "A"));
PrintItems(l);
Console.WriteLine(l.RemoveAll((s) => s == "Q"));
PrintItems(l);
}
示例8: FilterForApplicableTFMRIDPairs
public static List<TfmRidPair> FilterForApplicableTFMRIDPairs(List<TfmRidPair> tfmRidPairs,
string framework, string runtimeIdentifier)
{
if (framework != null)
{
tfmRidPairs.RemoveAll(x => !framework.Equals(x.framework));
}
if (runtimeIdentifier != null)
{
tfmRidPairs.RemoveAll(x => !runtimeIdentifier.Equals(x.runtimeIdentifier));
}
return tfmRidPairs;
}
示例9: OnHierarchyChange
void OnHierarchyChange()
{
emitters = new List<StudioEventEmitter>(Resources.FindObjectsOfTypeAll<StudioEventEmitter>());
if (!levelScope)
{
emitters.RemoveAll(x => PrefabUtility.GetPrefabType(x) != PrefabType.Prefab);
}
if (!prefabScope)
{
emitters.RemoveAll(x => PrefabUtility.GetPrefabType(x) == PrefabType.Prefab);
}
}
示例10: generate_btn_Click
// Event handlers
private void generate_btn_Click(object sender, EventArgs e)
{
status_bar.Value = 0;
string password = "";
List<char> choices = new List<char>();
if(lower_box.Checked) {
choices.AddRange(lower);
}
if(upper_box.Checked) {
choices.AddRange(upper);
}
if(num_box.Checked) {
choices.AddRange(numbers);
}
if(sym_box.Checked) {
choices.AddRange(symbols);
}
if(include_text.Text.Length > 0) {
choices.AddRange(include_text.Text.ToCharArray());
}
if(exclude_text.Text.Length > 0) {
for(int i = 0; i < exclude_text.Text.Length; i++) {
choices.RemoveAll(item => item == exclude_text.Text[i]);
}
}
char next;
for(int i = 0; i < (int)passlength_select.Value; i++) {
if(choices.Count > 0) {
next = choices[rand.Next(choices.Count)];
} else {
next = ' ';
}
if(repeat_box.Checked) {
choices.RemoveAll(item => item == next);
}
password += next;
}
status_bar.Value = 100;
pass_text.Text = password;
}
示例11: ReadFile
public static List<string> ReadFile(string filename)
{
List<string> listFileContent = new List<string>();
StringBuilder stringBuilder = new StringBuilder();
using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
using (StreamReader streamReader = new StreamReader(fileStream))
{
char[] fileContents = new char[_bufferSize];
int charsRead = streamReader.Read(fileContents, 0, _bufferSize);
// Can't do much with 0 bytes
//if (charsRead == 0)
// throw new Exception("File is 0 bytes");
while (charsRead > 0)
{
stringBuilder.Append(fileContents);
charsRead = streamReader.Read(fileContents, 0, _bufferSize);
}
string[] contentArray = stringBuilder.ToString().Split(new char[] { '\r', '\n' });
foreach (string line in contentArray)
{
listFileContent.Add(line.Replace("#", ""));
}
listFileContent.RemoveAll(s => string.IsNullOrEmpty(s));
}
}
return listFileContent;
}
示例12: Handle
public NanoHttpResponse Handle(NanoHttpRequest request)
{
try
{
var places = new List<string>(File.ReadAllLines(Strings.Places));
var place = request.Address.Substring(5);
bool found = false;
if (places.Contains(place))
{
found = true;
places.RemoveAll(s => s == place);
}
File.WriteAllLines(Strings.Places, places.ToArray());
return new NanoHttpResponse(StatusCode.Ok, (found?"Deleted ":"Not found ") + place);
}
catch (Exception e)
{
NotificationHandler.Instance.AddNotification("Не удалось обновить places.txt");
return new ErrorHandler(StatusCode.InternalServerError, e.ToString()).Handle(request);
}
}
示例13: Simp
private static List<int> Simp(int i)
{
List<int> list;
if (max_num >= i)
{
list = new List<int>(good_num);
list.RemoveAll(EndS);
}
else
{
list = new List<int>(good_num);
for (int j = 1; j < i - max_num + 1; j++)
{
if (IsSimp(max_num + j))
{
list.Add(max_num + j);
}
}
}
/*list = new List<int>();
for (int j = 1; j < i + 1; j++)
{
if (IsSimp(j))
{
Thread.Sleep(2);
list.Add(j);
}
}*/
return list;
}
示例14: OnGetValue
protected override void OnGetValue(PropertySpecEventArgs e)
{
base.OnGetValue(e);
var attributeList = new List<Attribute>();
attributeList.AddRange(e.Property.Attributes.ToList());
//check all of the attributes: if we find a dynamic one, evaluate it and possibly add/overwrite a static attribute
foreach (Attribute customAttribute in e.Property.Attributes)
{
if (customAttribute is DynamicReadOnlyAttribute)
{
attributeList.RemoveAll(x => x is ReadOnlyAttribute);
if (DynamicReadOnlyAttribute.IsDynamicReadOnly(propertyObject, e.Property.Name))
{
//condition is true: the dynamic attribute should be applied (as static attribute)
attributeList.Add(new ReadOnlyAttribute(true)); //add static read only attribute
}
}
}
e.Property.Attributes = attributeList.ToArray();
var propertyInfo = propertyObject.GetType().GetProperty(e.Property.Name);
var value = propertyInfo.GetValue(propertyObject, null);
var isNestedPropertiesObject = IsNestedExpandablePropertiesObject(propertyInfo);
// if nested properties object, wrap in DynamicPropertyBag to provide support for things like DynamicReadOnly
e.Value = isNestedPropertiesObject ? new DynamicPropertyBag(value) : value;
}
示例15: DataListTO
public DataListTO(string dataList, bool ignoreColumnDirection = false)
{
var fixedDataList = dataList.Replace(GlobalConstants.SerializableResourceQuote, "\"").Replace(GlobalConstants.SerializableResourceSingleQuote, "\'");
Inputs = new List<string>();
Outputs = new List<string>();
using (var stringReader = new StringReader(fixedDataList))
{
var xDoc = XDocument.Load(stringReader);
var rootEl = xDoc.Element("DataList");
if (rootEl != null)
{
if (ignoreColumnDirection)
{
Map(rootEl);
}
else
{
MapForInputOutput(rootEl);
}
}
}
Inputs.RemoveAll(string.IsNullOrEmpty);
Outputs.RemoveAll(string.IsNullOrEmpty);
}