Path.InvalidPathChars 字段

定义

注意

Please use GetInvalidPathChars or GetInvalidFileNameChars instead.

注意

Path.InvalidPathChars has been deprecated. Use GetInvalidPathChars or GetInvalidFileNameChars instead.

提供平台特定的字符数组,这些字符不能在传递到 Path 类的成员的路径字符串自变量中指定。

public: static initonly cli::array <char> ^ InvalidPathChars;
[System.Obsolete("Please use GetInvalidPathChars or GetInvalidFileNameChars instead.")]
public static readonly char[] InvalidPathChars;
[System.Obsolete("Path.InvalidPathChars has been deprecated. Use GetInvalidPathChars or GetInvalidFileNameChars instead.")]
public static readonly char[] InvalidPathChars;
public static readonly char[] InvalidPathChars;
[<System.Obsolete("Please use GetInvalidPathChars or GetInvalidFileNameChars instead.")>]
 staticval mutable InvalidPathChars : char[]
[<System.Obsolete("Path.InvalidPathChars has been deprecated. Use GetInvalidPathChars or GetInvalidFileNameChars instead.")>]
 staticval mutable InvalidPathChars : char[]
 staticval mutable InvalidPathChars : char[]
Public Shared ReadOnly InvalidPathChars As Char() 

字段值

Char[]
属性

示例

以下示例演示如何使用 InvalidPathChars 属性。

Console::WriteLine( "Path::AltDirectorySeparatorChar={0}", (Path::AltDirectorySeparatorChar).ToString() );
Console::WriteLine( "Path::DirectorySeparatorChar={0}", (Path::DirectorySeparatorChar).ToString() );
Console::WriteLine( "Path::PathSeparator={0}", (Path::PathSeparator).ToString() );
Console::WriteLine( "Path::VolumeSeparatorChar={0}", (Path::VolumeSeparatorChar).ToString() );
Console::Write( "Path::InvalidPathChars=" );
for ( int i = 0; i < Path::InvalidPathChars->Length; i++ )
   Console::Write( Path::InvalidPathChars[ i ] );
Console::WriteLine();

// This code produces output similar to the following:
// Note that the InvalidPathCharacters contain characters
// outside of the printable character set.
//
// Path.AltDirectorySeparatorChar=/
// Path.DirectorySeparatorChar=\
// Path.PathSeparator=;
// Path.VolumeSeparatorChar=:
Console.WriteLine("Path.AltDirectorySeparatorChar={0}",
    Path.AltDirectorySeparatorChar);
Console.WriteLine("Path.DirectorySeparatorChar={0}",
    Path.DirectorySeparatorChar);
Console.WriteLine("Path.PathSeparator={0}",
    Path.PathSeparator);
Console.WriteLine("Path.VolumeSeparatorChar={0}",
    Path.VolumeSeparatorChar);

Console.Write("Path.GetInvalidPathChars()=");
foreach (char c in Path.GetInvalidPathChars())
    Console.Write(c);
Console.WriteLine();
// This code produces output similar to the following:
// Note that the InvalidPathCharacters contain characters
// outside of the printable character set.
//
// Path.AltDirectorySeparatorChar=/
// Path.DirectorySeparatorChar=\
// Path.PathSeparator=;
// Path.VolumeSeparatorChar=:
Console.WriteLine("Path.AltDirectorySeparatorChar={0}", Path.AltDirectorySeparatorChar)
Console.WriteLine("Path.DirectorySeparatorChar={0}", Path.DirectorySeparatorChar)
Console.WriteLine("Path.PathSeparator={0}", Path.PathSeparator)
Console.WriteLine("Path.VolumeSeparatorChar={0}", Path.VolumeSeparatorChar)

Console.Write("Path.GetInvalidPathChars()=")
Dim c As Char
For Each c In Path.GetInvalidPathChars()
    Console.Write(c)
Next c
Console.WriteLine()

' This code produces output similar to the following:
' Note that the InvalidPathCharacters contain characters
' outside of the printable character set.
'
' Path.AltDirectorySeparatorChar=/
' Path.DirectorySeparatorChar=\
' Path.PathSeparator=;
' Path.VolumeSeparatorChar=:

注解

无法保证从此方法返回的数组包含文件和目录名称中无效的完整字符集。 完整的无效字符集可能因文件系统而异。 请参阅 GetInvalidPathChars() 备注,了解此字段返回的字符集是什么。

注意

如果认为代码可能与不受信任的代码在同一应用程序域中执行,请不要使用 InvalidPathCharsInvalidPathChars 是一个数组,因此可以覆盖其元素。 如果不受信任的代码会覆盖 的 InvalidPathChars元素,则可能会导致代码故障,并可能被利用。

适用于

另请参阅