我有2个.cs文件。一个包含字符串,另一个包含字符串。我想使用类中的字符串,但是当我向字符串添加“public”时,代码搞砸了。 这是类文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace DreamJ
{
public class second
{
public void Test()
{
WebClient webClient = new WebClient();
webClient.Headers.Add("User-Agent: Other");
webClient.Headers.Add("Accept", "*/*");
string content = webClient.DownloadString("https://example.com");
string result = content.Replace("\"", " ");
string more = result.Replace("},", "},\n");
}
}
}
我希望得到主要类文件的“更多”,例如:a.Send(更多)(无法显示)。我是c#的新手,请帮助我。 (抱歉我的英语不好)
答案 0 :(得分:0)
只需创建更多公共成员。要么是这个,要么从你的功能中返回更多。
解决方案1:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace DreamJ
{
public class second
{
public void Test()
{
WebClient webClient = new WebClient();
webClient.Headers.Add("User-Agent: Other");
webClient.Headers.Add("Accept", "*/*");
string content = webClient.DownloadString("https://example.com");
string result = content.Replace("\"", " ");
more = result.Replace("},", "},\n");
}
public string more
{
get;
set;
}
}
}
解决方案2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace DreamJ
{
public class second
{
public string Test()
{
WebClient webClient = new WebClient();
webClient.Headers.Add("User-Agent: Other");
webClient.Headers.Add("Accept", "*/*");
string content = webClient.DownloadString("https://example.com");
string result = content.Replace("\"", " ");
string more = result.Replace("},", "},\n");
return more;
}
}
}