将以下两个问题的代码给我1.使用C#实现一个泛型的ArrayList 2.使用C#正则表达式模拟弹幕过滤敏感词的功能,设定一部分敏感词,当用户输入一段话后,会将敏感词过滤为***
时间: 2023-03-05 15:57:28 浏览: 80
1 使用C#实现一个泛型的ArrayList:using System;
using System.Collections.Generic;
namespace GenericArrayList
{
class Program
{
static void Main(string[] args)
{
// Creating a Generic List
List<string> strList = new List<string>();
// Adding elements to the Generic List
strList.Add("one");
strList.Add("two");
strList.Add("three");
strList.Add("four");
strList.Add("five");
// Printing the Generic List
foreach (string str in strList)
{
Console.WriteLine(str);
}
}
}
}2. 使用C#正则表达式模拟弹幕过滤敏感词的功能,设定一部分敏感词,当用户输入一段话后,会将敏感词过滤为***:using System;
using System.Text.RegularExpressions;namespace SensitiveWordFilter
{
class Program
{
static void Main(string[] args)
{
// Set up the array of sensitive words
string[] sensitiveWords = new string[] { "badword1", "badword2", "badword3" }; // Get the user input
Console.WriteLine("Enter the text: ");
string inputText = Console.ReadLine(); // Filter the words
foreach(string word in sensitiveWords)
{
Regex regex = new Regex(word);
inputText = regex.Replace(inputText, "***");
} // Print out the filtered text
Console.WriteLine("Filtered text: " + inputText);
}
}
}