Using C#, I need a some code to use regular expressions to replace spaces inside of quotes with a pipe character (|). problem is that the string could contain multiple quoted expressions and I only want the spaces inside of quotes . I tried a few things but I am struggling with how to handle the variable number of words that could be inside of quotes, amongst other things. Here is some examp
使用C#,我需要一些代码来使用正则表达式来用管道字符(|)替换引号内的空格。 问题是该字符串可能包含多个带引号的表达式,而我只想要引号内的空格 。 我尝试了一些东西,但我正在努力处理可能在引号内的可变数量的单词,以及其他内容。 以下是可能输入的一些示例以及所需的输出: “word1 word2” - >“word1 | word2” “word1 word2”word3“word4 word5” - >“word1 | word2”word3“word4 | word5” word1“wo
I have a list (of objects), with one property in the object as a string. This property always contains single words and would like to loop through all sequential combinations in pairs, for example: word1 word2 word3 word4 word5 I am trying to write LINQ which will allow me to iterate through the data in the following format: word1 [space] word2 word2 [space] word3 word3 [space
我有一个(对象)列表,对象中有一个属性作为字符串。 该属性总是包含单个单词,并希望循环遍历所有顺序组合,例如: 字1 WORD2 WORD3 word4 的word5 我正在尝试编写LINQ,这将允许我按以下格式遍历数据: word1 [空格] word2 word2 [空格] word3 word3 [空格] word4 word4 [空格] word5 任何人都可以提出这样做的最有效的方法。 在我想要删除的时候,我有一大堆有条件的IF语句。 我想你想要: va
What is the best way to randomize the order of a generic list in C#? I've got a finite set of 75 numbers in a list I would like to assign a random order to, in order to draw them for a lottery type application. Shuffle any (I)List with an extension method based on the Fisher-Yates shuffle: private static Random rng = new Random(); public static void Shuffle<T>(this IList<T>
在C#中随机化通用列表的顺序的最佳方法是什么? 我在列表中有一个有限数量的75个数字,我想指定一个随机顺序,以便为抽奖类型的应用程序绘制它们。 使用基于Fisher-Yates shuffle的扩展方法对任何(I)List进行随机播放: private static Random rng = new Random(); public static void Shuffle<T>(this IList<T> list) { int n = list.Count; while (n > 1) { n--; int
I have two objects: public class Person1 { public string FirstName { get; set; } public string LastName { get; set; } } public class Person2 { public string FIRST_NAME { get; set; } public string LAST_NAME { get; set; } public int? Foo { get; set; } } The difference between the two is that the destination object has the additional property named Foo. I would like Automappe
我有两个对象: public class Person1 { public string FirstName { get; set; } public string LastName { get; set; } } public class Person2 { public string FIRST_NAME { get; set; } public string LAST_NAME { get; set; } public int? Foo { get; set; } } 两者之间的区别在于目标对象具有名为Foo的附加属性。 我希望Automapper在将Person1列表映射到Person2时使用Foo的目标值。 当我映射单
I have a list of Person objects class Person { string FirstName{get;set;} int Age {get;set;} } Now in this Person objects list Person1 has FirstName="Alan", Age=20 Person 2 has FirstName="Josephine", Age=21 I need to get a new List, where each list item has the first name concatenated with the age List I need: Alan:20 Josephine:21 ...so on I have this
我有一个Person对象列表 class Person { string FirstName{get;set;} int Age {get;set;} } 现在在这个Person对象列表中 Person1有FirstName =“Alan”,Age = 20 人2有FirstName =“Josephine”,年龄= 21 我需要得到一个新的列表,其中每个列表项都有与年龄连接的名字 我需要的清单: 艾伦:20 约瑟芬:21 ...等等 我到目前为止... var PersonConcatenatedList= from p in PersonList
I'm new to XML and C#. I want to load a dropdown list with specific items from an XML-file. I want to fill it with all the persons where cityname=City1 (Person1, Person2, Person3 and Person4). The problem is that all the persons displays in the dropdownbox on one single row, instead of one person on each row. Please help me Here is my XML: <country> <city> <cityna
我是新来的XML和C#。 我想从XML文件中加载一个包含特定项目的下拉列表。 我想填写cityname = City1(Person1,Person2,Person3和Person4)的所有人员。 问题在于,所有人都显示在单行上的下拉框中,而不是每行上的一个人。 请帮帮我 这是我的XML: <country> <city> <cityname>City1</cityname> <citynr>111</citynr> <person> <name>Person1<
I have a list of Persons which has children [same type]. I get the list from xml file. Scenario : Person : Id, Name, Gender, Age, Children [Class with fields] If personList has 1,2,5 Ids, 2 and 5 with children 3,4 and 6,7,8 respectively. I have to get the max id as 8. How do i get the max of Id from PersonList using lambda expression? You could try a combination of Concat and Selec
我有一个有子女[同类型]的人员名单。 我从XML文件中获取列表。 场景: 人:身份证,姓名,性别,年龄,儿童[与领域类] 如果personList具有1,2,5个ID, 2和5分别与儿童3,4和6,7,8。 我必须将最大id设为8。 如何使用lambda表达式从PersonList中获取Id的最大值? 你可以尝试Concat和SelectMany的组合(假设它只能嵌套一层): var maxId = personList.Concat(personList.SelectMany(p => p.Children)).Max(p =>
The point of this exercise is to make navigation between objects stateful. For example, having Person and Address with 1-1 association it should: If an address is assigned to a persons, then the person should be assigned to the address (and vice versa). If address is assigned to person1 and then to person2, then the person1 will have no address and person2 will. This is the piece of code
这个练习的要点是在有状态的对象之间进行导航。 例如,拥有1-1和1-1的联系人应该: 如果一个地址被分配给一个人,那么该人应该被分配到该地址(反之亦然)。 如果地址分配给person1,然后分配给person2,那么person1将没有地址,person2将会分配。 这是实现它的代码片段。 public class A { internal B a; public B Value { get { return a; } set { if (value
I would assume there's a simple LINQ query to do this, I'm just not exactly sure how. Please see code snippet below. class Program { static void Main(string[] args) { List<Person> peopleList1 = new List<Person>(); peopleList1.Add(new Person() { ID = 1 }); peopleList1.Add(new Person() { ID = 2 }); peopleList1.Add(new Person() { ID = 3 }
我会假设有一个简单的LINQ查询来做到这一点,我只是不完全知道如何。 请参阅下面的代码片段。 class Program { static void Main(string[] args) { List<Person> peopleList1 = new List<Person>(); peopleList1.Add(new Person() { ID = 1 }); peopleList1.Add(new Person() { ID = 2 }); peopleList1.Add(new Person() { ID = 3 }); List<Person> people
This question already has an answer here: Multiple “order by” in LINQ 6 answers 您可以使用ThenBy和ThenByDescending扩展方法: foobarList.OrderBy(x => x.Foo).ThenBy( x => x.Bar)
这个问题在这里已经有了答案: LINQ 6中的多个“order by”回答 您可以使用ThenBy和ThenByDescending扩展方法: foobarList.OrderBy(x => x.Foo).ThenBy( x => x.Bar)