在C#中System.IO.DriveInfo有属性DriveType.
System.IO.DriveType 是一个枚举:
public enum DriveType
{
Unknown = 0,
//
// Summary:
// The drive does not have a root directory.
NoRootDirectory = 1,
Removable = 2,
Fixed = 3,
Network = 4,
CDRom = 5,
Ram = 6,
}
Run Code Online (Sandbox Code Playgroud)
我怀疑这是一个没有驱动器号的卷.但使用:
System.IO.DriveInfo.GetDrives();
Run Code Online (Sandbox Code Playgroud)
没有驱动器号没有列出我的音量.
是NoRootDirectory用于任何其他类型的卷/驱动器还是System.IO.DriveInfo.GetDrives()只是不显示它们?
有什么区别:
$A="Something"
Run Code Online (Sandbox Code Playgroud)
和
$A.Value="Something"
Run Code Online (Sandbox Code Playgroud)
我看到这只在.Value使用时才有效:
function main
{
$A="Original A"
$B="Original B"
SetByRef1 ([ref]$A)
SetByRef2 ([ref]$B)
$A
$B
#output: Changed A
#output: Original B
}
function SetByRef1([ref]$A)
{
$A.Value = "Changed A"
}
function SetByRef2([ref]$B)
{
$B = "Changed B"
}
main
Run Code Online (Sandbox Code Playgroud)
我想,这$B = "Changed B"是定义一个新变量B,而$A.Value = "Changed A"只是改变内容,但我还没有找到确认.
(我确定这是重复的,但我还没找到)
为什么这个分配会产生一个comile错误:Constant value '-2147483648' cannot be converted to a 'ulong'我必须使用unchecked (...)这个案例?
ulong xDummy30 = (1 << 30); // works
ulong xDummy31 = (1 << 31); // ERROR 25 Constant value '-2147483648' cannot be converted to a 'ulong'
ulong xDummy32 = (1 << 32); // works
Run Code Online (Sandbox Code Playgroud)
使用它代替工作:
ulong xDummy31a = unchecked((ulong)(1 << 31));
// or
ulong xDummy31b = (1ul << 31); // comment from Regis Portalez
Run Code Online (Sandbox Code Playgroud) 我在c ++中有一个简单的函数(不是类的方法)
__declspec(dllexport) extern "C" void __stdcall TestFunc();
Run Code Online (Sandbox Code Playgroud)
我试着从c#中调用它:
[DllImport("ImportTest.dll")]
public static extern void TestFunc();
...
TestFunc();
Run Code Online (Sandbox Code Playgroud)
它抛出了"无法找到入口点"的例外.
怎么了?
感谢你们对我的帮助 :)
我的函数将枚举类型获取为字符串,我需要对其进行验证。
为什么parsedType(s)在这里为null?
var parsedType1 = Type.GetType("System.Windows.TextAlignment.Left");
var parsedType2 = Type.GetType("System.Windows.TextAlignment");
Run Code Online (Sandbox Code Playgroud)
虽然这个有效吗?
var parsedType3 = Type.GetType("System.String");
Run Code Online (Sandbox Code Playgroud)