有一个List<BuffRecord> buffRecords [Serializable] public struct BuffRecord { // 记录buff来源…
- User
有一个List buffRecords [Serializable] public struct BuffRecord { // 记录buff来源 public string buffName;
public CardKeyWordType keywordType; } 想把这个list 按照 这样的buffName: keywordType +换行 拼成一个string怎么写呢 - Assistant
要将
List<BuffRecord>转换为所需格式的字符串,你可以使用 LINQ 和StringBuilder来简洁地实现。以下是一个示例代码:using System; using System.Collections.Generic; using System.Text; public enum CardKeyWordType { // 示例枚举类型 Type1, Type2, Type3 } [Serializable] public struct BuffRecord { public string buffName; public CardKeyWordType keywordType; } public class Program { public static void Main() { List<BuffRecord> buffRecords = new List<BuffRecord> { new BuffRecord { buffName = "Buff1", keywordType = CardKeyWordType.Type1 }, new BuffRecord { buffName = "Buff2", keywordType = CardKeyWordType.Type2 }, new BuffRecord { buffName = "Buff3", keywordType = CardKeyWordType.Type3 } }; string result = ConvertBuffRecordsToString(buffRecords); Console.WriteLine(result); } public static string ConvertBuffRecordsToString(List<BuffRecord> buffRecords) { StringBuilder sb = new StringBuilder(); foreach (var record in buffRecords) { sb.AppendLine($"{record.buffName}: {record.keywordType}"); } return sb.ToString(); } } - User
public List keywords; // 天赋列表
[System.Serializable] public class KeywordInfo { public CardKeyWordType keywordType; public string name; // 天赋名称 public string description; // 天赋描述 } 从keywords 里面选出一个keywordType = record.keywordType ,并且用他的name替换sb.AppendLine($“{record.buffName}: {record.keywordType}”);里面的record.keywordType - Assistant
要从 列表中查找与 相匹配的 ,并使用其 替换原来的 ,你可以在 方法中进行相应的查找和替换。以下是修改后的代码:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.