namespace System
{
public sealed class String
{
public unsafe static string Concat(string? str1, string? str2)
{
return "Test";
}
}
}
There is no problem with compilation, but after declaring the variable and concatenating it, p2 is printed. Name has no result, but prints p1. Name is no problem
using System.Runtime.InteropServices;
using System;
using System.Threading;
unsafe
{
var str1 = "Hello";
var str2 = "World";
var p1 = new Person("Hello" + "World");
Console.WriteLine(p1.Name); // √
var p2 = new Person(str1 + str2);
Console.WriteLine(p2.Name); // x
Thread.Sleep(1000);
}
public class Person {
public string Name;
public Person(string name){
Name = name;
}
}
Let's say string implements Concat:
There is no problem with compilation, but after declaring the variable and concatenating it, p2 is printed. Name has no result, but prints p1. Name is no problem