Path.InvalidPathChars 字段

定义

警告

此 API 现已过时。

提供平台特定的字符数组,这些字符不能在传递到 Path 类的成员的路径字符串参数中指定。Provides a platform-specific array of characters that cannot be specified in path string arguments passed to members of the Path class.

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

字段值

Char[]
属性

示例

下面的示例演示 InvalidPathChars 属性的用法。The following example demonstrates the use of the InvalidPathChars property.

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=:

注解

从此方法返回的数组不保证包含在文件和目录名称中无效的完整字符集。The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names. 完整的无效字符集可能因文件系统而异。The full set of invalid characters can vary by file system. 例如,在基于 Windows 的桌面平台上,无效路径字符可能包括 ASCII/Unicode 字符1到31、引号(")、小于(<)、大于(>)、管道(|)、backspace (\b)、null (\ 0)和制表符(\t)。For example, on Windows-based desktop platforms, invalid path characters might include ASCII/Unicode characters 1 through 31, as well as quote ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0) and tab (\t).

注意

如果你认为你的代码可能在不受信任的代码所在的应用程序域中执行,请不要使用 InvalidPathCharsDo not use InvalidPathChars if you think your code might execute in the same application domain as untrusted code. InvalidPathChars 是数组,因此可以覆盖其元素。InvalidPathChars is an array, so its elements can be overwritten. 如果不受信任的代码覆盖 InvalidPathChars的元素,则可能会导致您的代码以可利用的方式发生故障。If untrusted code overwrites elements of InvalidPathChars, it might cause your code to malfunction in ways that could be exploited.

适用于

另请参阅