小编rrc*_*709的帖子

如何将 PC 中的本地文件路径转换为网络相对路径或 UNC 路径?

String machineName = System.Environment.MachineName;
String filePath = @"E:\folder1\folder2\file1";
int a = filePath.IndexOf(System.IO.Path.DirectorySeparatorChar);
filePath = filePath.Substring(filePath.IndexOf(System.IO.Path.DirectorySeparatorChar) +1);
String networdPath = System.IO.Path.Combine(string.Concat(System.IO.Path.DirectorySeparatorChar, System.IO.Path.DirectorySeparatorChar), machineName, filePath);
Console.WriteLine(networdPath);
Run Code Online (Sandbox Code Playgroud)

我使用String.Concat和编写了上述代码Path.Combine以获取网络路径。但这只是一种解决方法,而不是具体的解决方案,可能会失败。是否有获取网络路径的具体解决方案?

c# vb.net

5
推荐指数
1
解决办法
1610
查看次数

在JavaScript中,为什么不能修改常量String,但可以修改常量数组

const name = 1;
name = 2;
Run Code Online (Sandbox Code Playgroud)

执行此JavaScript时出现错误:

TypeError: Assignment to constant variable.
    at Object.<anonymous> (/home/user01/JavaScript/scope.js:2:6)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
Run Code Online (Sandbox Code Playgroud)

但是,在执行以下语句时,代码会成功执行.

const arr = [1,2,3];
arr[1] = 5;
Run Code Online (Sandbox Code Playgroud)

为什么我们能够修改数组,即使它被声明为常量.

javascript arrays const

4
推荐指数
1
解决办法
629
查看次数

标签 统计

arrays ×1

c# ×1

const ×1

javascript ×1

vb.net ×1