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

标签 .net-core

我试图让以下代码在 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/

相关文章:

c# - 找不到方法 : 'System.Threading.Tasks.Task` 1<Microsoft. Rest.ServiceClientCredentials> Microsoft.Rest.Azure.Authentication.UserTokenProvider

sql-server - 迁移不起作用

.net-core - 用ffprobe处理内存中的mp4文件

c# - Webapi 在 docker-compose 中看不到 MongoDB

.NET Standard、.NET Core 和 .NET Framework 项目解决方案的 .NET 命名约定

razor - 如何将异步值分配给 Razor 组件 [参数] 属性?

用于计算密集型工作的 Azure FunctionApps 与 Azure 应用服务

c# - HttpClient GetAsync 与 URL 中的散列

.net-core - 找不到包 'Microsoft.NETCore.App' 的编译库位置

c# - .NET Core 中是否内置了自动转义无效 HTTP header 字符的支持?