我试着阅读了关于这个主题的其他帖子,但不太明白。
我在C#中有一个列表,我想用所有相同的键将其放入字典中。清单是这样的
string[] IN ={"Against","Like","Upon","Through","Of","With","Upon","On","Into","From","by","that","In","About","For"
我有一台Dictionary<int, List<string>> enrolledStudents key是一个整数,这是一个纸质代码。value是一个字符串列表,其中的字符串是学生姓名 我想知道的是如何检查enrolledStudents中的这个列表中是否有一个string s 例如 if(string s in List<string> of enrolledStudents){
return enrolledStudent.key;
}
在C#中是否可以创建一个列表并从一个变量或类似的变量中命名它?
假设我有一个包含10行的列表:
a,b,c,d,e,f,g,h,i,j
我可以从这个列表中列出10个列表,每个列表都有一个类似行的名称吗?
有点像
List<string> myList = new List<string>();
foreach (var line in myList)
{
List<string> line = new List<string>();
}
我想要的是做一些列表来存储数据,但是在程序运行之前我不知道名字,所以它需要动态地生成这些名称。
我正在尝试创建一个Dictionary<string,int>项目列表。我不确定如何在列表中添加项目,以及如何在遍历列表时取回值。我想在C#中使用它,如下所示:
public List<Dictionary<string,int>> MyList= new List<Dictionary<string,int>>();
我想在C#中以最有效和最有效的方式随机排列一个有限列表。我的尝试如下。
/*===================================*
* Compile it to produce Shuffle.exe *
* ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
class Program
{
static void Main(string[] ar
我有一个如下的扩展方法:
public static T GetValueAs<T, R>(this IDictionary<string, R> dictionary, string fieldName)
where T : R
{
R value;
if (!dictionary.TryGetValue(fieldName, out value))
return default(T);
return (T)value;
}
目前,我可以通过以下方式使用它:
var dictionary = new Dicti
我正在尝试阻止在列表中添加已存在于C#中的项目。下面的代码遍历datatable行。如您所见,行的类型为List<CubeReportRow>
数据表行确实包含重复项。我需要检查数据表中的rowName是否已经存在于List<CubeReportRow>类型的行对象中。请参见我在foreach循环中设置的条件。当我尝试按行名检查时,它显示无法将字符串转换为CubeReportRow类型。如何检查它在行集合中是否存在。
CubeReportRow类
public class CubeReportRow
{
public string RowNam
给定一个泛型类型,包括
List<string>
Nullable<Int32>
如何获取C#的通用名称?
var t = typeof(Nullable<DateTime>);
var s = t.GetGenericTypeDefinition().Name + "<" + t.GetGenericArguments()[0].Name + ">";
这会产生"Nullable`1<DateTime>",但我需要"Nullable<DateTime>
如何从Web C#方法中的操作参数中获取所有字符串值--我使用了以下代码:
public override void OnActionExecuting(HttpActionContext actionContext)
{
Dictionary<string, object> list = actionContext.ActionArguments;
for (int index = 0; index < list.Count; index++)
{
// need to all variables if the data
我正在努力理解这些文件:
我的目标只是使用 (DotNet5.0)加载System.Text.Json.JsonSerializer。从C#到JSON的步骤很简单:
private class DataElement<T>
{
public string vr { get; set; }
public List<T> Value { get; set; }
}
[...]
var dataset = new Dictionary<string, object>();
dataset.Add("00100021", new
我有一个文件,是写DOS格式,我需要替换一些字符到其他。为此,我创建了一本字典,现在我必须阅读流中的每一行内容,并在执行过程中替换我的值。
我在C#中创建了这段代码,但是,我非常怀疑这是否可行,因为我认为C#字典类必须有一种更简单的方法来实现这一可能是常见的操作。任何反馈都是非常感谢的!
public Dictionary<char, string> Chars { get; set; } = new Dictionary<char, string>();
// Called in my constructor
public void CreateDi
如何转换以下F# (它将整数转换为字符串并替换某些字符并将其反转,仅举一个例子)。我真正需要的是如何使用List ( C#)折叠到C# (使用Aggregate )
// Convert an integer to string, replace some characters and reverse it
let convert (aInt:int) =
let m = [ '0', 'O'; '1', 'l'; '8', 'B'; ....] |> Map.ofList
s
实例化时,给字典分配的最佳方法是什么?
例如,在我使用myDictionary所做的下面,如何对myList进行操作
Dictionary<int, string> myDictionary = new Dictionary<int, string>()
{
// this does not work. how to make it work?
(0, "first"),
(1, "second")
};
// here's how it's done with List<T>
Lis
假设我在Python中有以下代码(是的,这个问题是关于c#的--这只是一个例子)
string = "{entry1} {entry2} this is a string"
dictionary = {"entry1": "foo", "entry2": "bar"}
print(string.format(**dictionary))
# output is "foo bar this is just a string"
在此字符串中,它将使用entry1将{entry2}和{entry2}从
我有一个字典,如下所示:
var objListColor = new List<String>() { "Red", "Blue", "Green", "Yellow" };
var objListDirection = new List<String>() { "East", "West", "North", "South" };
var dictFrom = new Dictionary<int, List<String&g
我们是否可以在List <T>中使用两个不同的类型参数,或者在类类型中再添加一个参数?
例如:
public class ClassA
{
public int a {get;set;}
public int b {get;set;}
}
我需要在不编辑ClassA的情况下在列表中添加更多属性
public string c {get;set;}
public List<ClassA, c> list = new List<ClassA, c>
我应该能够在列表中访问c#。
item[0].a
item[0].b
item[0].c
我正在尝试做一个支持多列的C# Android列表视图。我在这里找到了一些如何创建列表视图的代码:
但是,这是Java代码,所以我将其转换为C#,如下所示:
// List view control
ListView list = (ListView) FindViewById(Resource.Id.mylist);
List<Dictionary<string, string>> mylist = new List<Dictionary<string, string>>();
D
嘿,我是C#的新手(或者编程,因为我以前只学过html和css ),我只是在玩泛型,我做了一本小字典。搜索单词和东西是没有问题的,但是当我搜索一个与我的单词不匹配的词时,它会弹出并出错,我如何解决这个问题,请帮助!
for (int i = 1; i <= 10; i++)
{
Dictionary<string, string> fivewordDictionary = new Dictionary<string, string>();
fivewordDictionary.Add("hello", "Saying gr
如何在文本文件中查找字符串或列表。如果我有一个文本文件,只有单词,随机单词,而不是句子,我如何在其中找到一个字符串。假设我接受用户输入,如何测试或检查用户输入的字符串是否存在于文本文件中。
到目前为止,我有这样的想法:
x = open('sample.txt')
for a in x:
b = a.split() #converts the string from the txt to a list
c = input('enter: ') #user input
if any(c in a for a in b):
我有两个类: consumableItems.cs和items.cs,所以基本上,我所要做的就是将items.cs的属性继承到consumableItems.cs
我到目前为止所做的事情如下:
class Item
{
public List<string> itemNames = new List<string>();
public List<int> itemEffects = new List<int>();
}
class consumableItems : Item
{
new public List<
我得到了具有字符串属性的结构集合。给定一个字符串数组,我想检查是否有内部字符串与数组中的一些字符匹配的结构。我是这样做的:
struct S
{
public string s { get; set; }
}
private List<S> List = new List<S>(); // populated somewhere else
public bool Check(params string[] arr)
{
return (from s1 in List