gpt4 book ai didi

.net-core - dotnet 核心的 String.Copy 替代方案

转载 作者:行者123 更新时间:2023-12-02 04:03:40 24 4
gpt4 key购买 nike

我试图让以下代码在 ubuntu linux 上运行的 dotnet core 中工作 - 但在这一行出现“字符串不包含复制定义”编译错误 - 显然 String.Copy 不受支持dotnet 核心:

         Attendance = String.Copy(markers) };

在 dotnet Core 中进行浅字符串复制的最佳方法是什么?我应该使用 string.CopyTo 吗?

谢谢

//I want to add an initial marker to each record
//based on the number of dates specified
//I want the lowest overhead when creating a string for each record

string markers = string.Join("", dates.Select(p => 'U').ToArray());
return logs.Aggregate( new List<MonthlyAttendanceReportRow>(), (rows, log) => {
var match = rows.FirstOrDefault(p => p.EmployeeNo == log.EmployeeNo);
if (match == null) {
match = new MonthlyAttendanceReportRow() {
EmployeeNo = log.EmployeeNo,
Name = log.FirstName + " " + log.LastName,
Attendance = String.Copy(markers) };
rows.Add(match);
} else {
}
return rows;
});

最佳答案

为了完成罗杰森的回答,您可以使用一个扩展方法来完成您正在寻找的事情。

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

namespace CSharp_Shell
{
public static class ext{
public static string Copy(this string val){
return new String(val.ToArray());
}
}

public static class Program
{
public static void Main()
{
string b = "bbb";
var a = b.Copy();
Console.WriteLine("Values are equal: {0}\n\nReferences are equal: {1}.", Object.Equals(a,b), Object.ReferenceEquals(a,b));
}
}
}

关于.net-core - dotnet 核心的 String.Copy 替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40550039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com