我想知道那些getter和setter声明之间的区别是什么,以及是否有一个首选方法(以及为什么).第一个可以由Visual Studio自动生成.其他人怎么样?谢谢
1
string _myProperty { get; set; }
Run Code Online (Sandbox Code Playgroud)
第2
string _myProperty;
public string myProperty
{
get { return _myProperty; }
set { _myProperty = value; }
}
Run Code Online (Sandbox Code Playgroud)
第3
string _myProperty;
public string getMyProperty()
{
return this._myProperty;
}
public void setMyProperty(string value)
{
this._myProperty = value;
}
Run Code Online (Sandbox Code Playgroud) 有了2个ArrayList,我想知道将第一个转换成第二个的"副本"的最佳方法是
myFirstArray.clear();
myFirstArray.addAll(mySecondArray);
Run Code Online (Sandbox Code Playgroud)
要么
myFirstArray = mySecondArray.clone();
Run Code Online (Sandbox Code Playgroud)
这两种方法之间的主要区别是什么,哪种方法是优选的,还有另一种"更容易"或"更清洁"的解决方案.谢谢你的任何提示
编辑:我使用此副本替换当前使用的项目数组,我将在下一个循环中存储我将使用的项目.在循环结束时,我用我的futurArrayList替换了我的currentArrayList,并清除了我的futurArraylist以便在其中添加新项目(我希望它足够清晰)
所以这是我的问题,我正在尝试将文本文件的内容作为字符串,然后解析它.我想要的是一个包含每个单词的选项卡,只包含单词(没有空白,没有退格,没有\n ......)我正在做的是使用一个函数LireFichier将包含文件中的文本的字符串发回给我(工作正常因为它显示正确)但是当我尝试解析它失败并开始对我的字符串进行随机连接时我不明白为什么.这是我正在使用的文本文件的内容:
truc,
ohoh,
toto, tata, titi, tutu,
tete,
Run Code Online (Sandbox Code Playgroud)
这是我的最后一个字符串:
;tete;;titi;;tata;;titi;;tutu;
Run Code Online (Sandbox Code Playgroud)
应该是:
truc;ohoh;toto;tata;titi;tutu;tete;
Run Code Online (Sandbox Code Playgroud)
这是我写的代码(所有使用都可以):
namespace ConsoleApplication1{
class Program
{
static void Main(string[] args)
{
string chemin = "MYPATH";
string res = LireFichier(chemin);
Console.WriteLine("End of reading...");
Console.WriteLine("{0}",res);// The result at this point is good
Console.WriteLine("...starting parsing");
res = parseString(res);
Console.WriteLine("Chaine finale : {0}", res);//The result here is awfull
Console.ReadLine();//pause
}
public static string LireFichier(string FilePath) //Read the file, send back a string with the text
{
StreamReader streamReader = …Run Code Online (Sandbox Code Playgroud)