2

I'm trying to get the following code to work in dotnet core running on ubuntu linux - but getting a "string does not contain a definition for copy" compile error on this line - where apparently String.Copy is not supported in dotnet-core:

         Attendance = String.Copy(markers) };

What are the best ways of doing a shallow string copy in dotnet Core? Should I use string.CopyTo?

Thanks

//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;
 });
onemorecupofcoffee
  • 2,237
  • 1
  • 15
  • 21

2 Answers2

3

To complete Rogerson's answer, you can have an extension method which will do the exact thing that you are looking for.

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));
        }
    }
}
m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
Ali Alp
  • 691
  • 7
  • 10
2

Try this:

string b = "bbb";
var a = new String(b.ToArray());
Console.WriteLine("Values are equal: {0}\n\nReferences are equal: {1}.", Object.Equals(a,b), Object.ReferenceEquals(a,b));

You can see it running on this fiddle.

Ali Alp
  • 691
  • 7
  • 10