Path.DirectorySeparatorChar Veld
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Biedt een platformspecifiek teken dat wordt gebruikt om mapniveaus te scheiden in een padtekenreeks die een hiërarchische bestandssysteemorganisatie weerspiegelt.
public: static initonly char DirectorySeparatorChar;
public static readonly char DirectorySeparatorChar;
staticval mutable DirectorySeparatorChar : char
Public Shared ReadOnly DirectorySeparatorChar As Char
Waarde van veld
Voorbeelden
In het volgende voorbeeld worden Path veldwaarden weergegeven op Windows en op Unix-systemen. Houd er rekening mee dat Windows de slash (die wordt geretourneerd door het veld AltDirectorySeparatorChar) of de backslash (die wordt geretourneerd door het DirectorySeparatorChar-veld) ondersteunt als padscheidingstekens, terwijl unix-systemen alleen de slash ondersteunen.
using System;
using System.IO;
class Program
{
static void Main()
{
Console.WriteLine($"Path.DirectorySeparatorChar: '{Path.DirectorySeparatorChar}'");
Console.WriteLine($"Path.AltDirectorySeparatorChar: '{Path.AltDirectorySeparatorChar}'");
Console.WriteLine($"Path.PathSeparator: '{Path.PathSeparator}'");
Console.WriteLine($"Path.VolumeSeparatorChar: '{Path.VolumeSeparatorChar}'");
var invalidChars = Path.GetInvalidPathChars();
Console.WriteLine($"Path.GetInvalidPathChars:");
for (int ctr = 0; ctr < invalidChars.Length; ctr++)
{
Console.Write($" U+{Convert.ToUInt16(invalidChars[ctr]):X4} ");
if ((ctr + 1) % 10 == 0) Console.WriteLine();
}
Console.WriteLine();
}
}
// The example displays the following output when run on a Windows system:
// Path.DirectorySeparatorChar: '\'
// Path.AltDirectorySeparatorChar: '/'
// Path.PathSeparator: ';'
// Path.VolumeSeparatorChar: ':'
// Path.GetInvalidPathChars:
// U+007C) U+0000) U+0001) U+0002) U+0003) U+0004) U+0005) U+0006) U+0007) U+0008)
// U+0009) U+000A) U+000B) U+000C) U+000D) U+000E) U+000F) U+0010) U+0011) U+0012)
// U+0013) U+0014) U+0015) U+0016) U+0017) U+0018) U+0019) U+001A) U+001B) U+001C)
// U+001D) U+001E) U+001F)
//
// The example displays the following output when run on a Linux system:
// Path.DirectorySeparatorChar: '/'
// Path.AltDirectorySeparatorChar: '/'
// Path.PathSeparator: ':'
// Path.VolumeSeparatorChar: '/'
// Path.GetInvalidPathChars:
// U+0000
Imports System.IO
Module Program
Sub Main()
Console.WriteLine($"Path.DirectorySeparatorChar: '{Path.DirectorySeparatorChar}'")
Console.WriteLine($"Path.AltDirectorySeparatorChar: '{Path.AltDirectorySeparatorChar}'")
Console.WriteLine($"Path.PathSeparator: '{Path.PathSeparator}'")
Console.WriteLine($"Path.VolumeSeparatorChar: '{Path.VolumeSeparatorChar}'")
Dim invalidChars = Path.GetInvalidPathChars()
Console.WriteLine($"Path.GetInvalidPathChars:")
For ctr As Integer = 0 To invalidChars.Length - 1
Console.Write($" U+{Convert.ToUInt16(invalidChars(ctr)):X4} ")
if (ctr + 1) Mod 10 = 0 Then Console.WriteLine()
Next
Console.WriteLine()
Console.WriteLine("Hello World!")
End Sub
End Module
' The example displays the following output when run on a Windows system:
' Path.DirectorySeparatorChar: '\'
' Path.AltDirectorySeparatorChar: '/'
' Path.PathSeparator: ';'
' Path.VolumeSeparatorChar: ':'
' Path.GetInvalidPathChars:
' U+007C) U+0000) U+0001) U+0002) U+0003) U+0004) U+0005) U+0006) U+0007) U+0008)
' U+0009) U+000A) U+000B) U+000C) U+000D) U+000E) U+000F) U+0010) U+0011) U+0012)
' U+0013) U+0014) U+0015) U+0016) U+0017) U+0018) U+0019) U+001A) U+001B) U+001C)
' U+001D) U+001E) U+001F)
'
' The example displays the following output when run on a Linux system:
' Path.DirectorySeparatorChar: '/'
' Path.AltDirectorySeparatorChar: '/'
' Path.PathSeparator: ':'
' Path.VolumeSeparatorChar: '/'
' Path.GetInvalidPathChars:
' U+0000
Opmerkingen
AltDirectorySeparatorChar en DirectorySeparatorChar beide geldig zijn voor het scheiden van mapniveaus in een padtekenreeks.
Wanneer u .NET Core gebruikt om toepassingen te ontwikkelen die op meerdere platforms worden uitgevoerd:
Als u het adreslijstscheidingsteken liever coderen, moet u het slashteken (
/) gebruiken. Het is het enige herkende mapscheidingsteken op Unix-systemen, zoals de uitvoer uit het voorbeeld laat zien en is het AltDirectorySeparatorChar op Windows.Gebruik tekenreekssamenvoeging om het padscheidingsteken tijdens runtime dynamisch op te halen en op te nemen in bestandssysteempaden. Bijvoorbeeld:
separator = Path.DirectorySeparatorChar; path = $"{separator}users{separator}user1{separator}";separator = Path.DirectorySeparatorChar path = $"{separator}users{separator}user1{separator}"U kunt de waarde ook ophalen uit de eigenschap AltDirectorySeparatorChar, omdat deze hetzelfde is op zowel Windows- als Unix-systemen.
AltDirectorySeparatorChar De eigenschap ophalen
Als uw toepassing niet platformoverschrijdend is, kunt u het scheidingsteken gebruiken dat geschikt is voor uw systeem.