none
看不懂这些语句是啥意思,请老师们帮忙解释一下,谢谢!!! RRS feed

  • 问题

  • 各位老师,这段语句是什么意思呢?请帮忙解释一下,越详细越好,谢谢!!!

    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Data\Palette\Palette.txt"))
                {
                    using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Data\Palette\Palette.txt", Encoding.UTF8))
                    {
                        string temp = sr.ReadToEnd();
                        //
                        Palette obj = JObject.Parse(temp).ToObject<Palette>();
                        new PaletteHelper().ReplacePalette(obj);
                    }
                }

    2019年8月2日 6:54

答案

  • Hi,

    If语句是用来判断该项目的对应目录下是否存在“Palette.txt”文件。如果存在的话,就将该文件中的内容读取并存放在string字段“temp”中。

    至于方法“JObject.Parse(temp).ToObject<Palette>()”是三方库中的方法,用于将string字段转换为想要的“Palette”类型。详情可以参考“JObject.Parse Method (String)”。

    而最后的“new PaletteHelper().ReplacePalette(obj)”也属于三方库中的自定义类和方法,你应该看一下它的使用文档。

    Regards,

    Kyle

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年8月2日 9:07
    版主
  • Hi,

    ..\表示的是当前目录的上一级目录。比如现在有路径“D:\folderA\folderB\”,那么“D:\folderA\folderB\..\”表示的就是“D:\folderA\”。

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年8月4日 12:34
    版主

全部回复

  • Hi,

    If语句是用来判断该项目的对应目录下是否存在“Palette.txt”文件。如果存在的话,就将该文件中的内容读取并存放在string字段“temp”中。

    至于方法“JObject.Parse(temp).ToObject<Palette>()”是三方库中的方法,用于将string字段转换为想要的“Palette”类型。详情可以参考“JObject.Parse Method (String)”。

    而最后的“new PaletteHelper().ReplacePalette(obj)”也属于三方库中的自定义类和方法,你应该看一下它的使用文档。

    Regards,

    Kyle

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年8月2日 9:07
    版主
  • 老师,谢谢你的指导,看完你的说明我大概是了解这段语句的意思了。

    我还想向你请教:我在项目里找到了Palette.txt文件,但语句这样写:@"..\..\Data\Palette\Palette.txt“前边的..\..\有啥讲究呢?

    请老师指导,谢谢!!!

    2019年8月2日 11:31
  • Hi,

    ..\表示的是当前目录的上一级目录。比如现在有路径“D:\folderA\folderB\”,那么“D:\folderA\folderB\..\”表示的就是“D:\folderA\”。

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年8月4日 12:34
    版主