【发布时间】:2019-07-01 13:43:20
【问题描述】:
我需要创建一个结构,将后者从两个字符串中移出并将其带到一个新字符串中。示例字符串“世界” 字符串“书” 输出“wboorolkd” 我构建了结构,但我无法在这里得到我所做的输出
我是 C# 新手
using System.Text;
using System.Threading.Tasks;
namespace myprogram_Struct
{
class Program
{
static void Main(string[] args)
{
Person person1 = new Person();
Console.WriteLine(person1.name);
person1.SetName("david");
Console.WriteLine(person1.name);
Person person2 = new Person("sarah");
Console.WriteLine(person2.name);
Console.ReadKey();
}
}
}
public struct Person
{
public string name;
public Person(string nm)
{
name = nm;
}
public void SetName(string newName)
{
name = newName;
}
}
【问题讨论】:
-
您的代码没有任何逻辑来实现您上面提到的功能。您需要先尝试编写该逻辑,如果遇到任何问题,请返回此处。逻辑是将两个字符串逐个字符压缩并从中创建一个新字符串。提示:字符串是字符的集合..
-
如果一个字符串比另一个长,应该怎么做?
-
到目前为止给出的解决方案仅限于两个字符串,这是您想要的 - 还是您想要组合 x 个字符串的解决方案?
标签: c# arrays string class struct