我是C#的新手(6个月的工作经验),但它似乎与Java非常相似,所以我觉得在家里.
但是,今天我尝试实现IComparer接口,并想知道它为什么给我一个错误:
public class AlphabeticalReportSort : IComparer
{
int Compare(Object x, Object y)
{
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
看起来它需要你实现它:
public class AlphabeticalReportSort : IComparer
{
int IComparer.Compare(Object x, Object y)
{
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
我没有注意到接口声明中需要这个的任何东西,而且在C#中你通常不需要这样做.
谁知道为什么?
昨天我在 Visual Studio 的表单设计器中编辑了一个表单。当我今天回到它时,设计师什么也没展示。我可以打开属性窗口,选择所有不同的组成组件并编辑它们的属性,但它们没有显示。应用程序构建良好,表单可以照常运行。
我尝试了几种不同的解决方案,例如检查 .csproj 文件是否包含 form.Designer.cs,但没有任何效果。
奇怪的是,我在本周早些时候确实看到了这个问题,但当我喝完咖啡休息回来后解锁计算机时,它自行修复了。
有什么建议么?
我在选项页面的预先存在的WixBootstrapper主题中添加了一个复选框:
<Checkbox Name="MyCheckbox" X="11" Y="217" Width="17" Height="17" TabStop="yes" FontId="3" HideWhenDisabled="yes" />
Run Code Online (Sandbox Code Playgroud)
在我的捆绑包中,我将此复选框的值传递给MSI:
<MsiPackage DisplayInternalUI="no" SourceFile="..\WixInstaller\bin\$(var.Configuration)\myinstaller.msi" Id="MainPackage">
<MsiProperty Name="INSTALLDIR" Value="[InstallFolder]" />
<MsiProperty Name="CHECKED" Value="[MyCheckbox]" />
Run Code Online (Sandbox Code Playgroud)
除我希望默认情况下选中复选框外,此方法工作正常。
我看过定义解决方案的地方:
<Property Id="myprop" Value="1" />
Run Code Online (Sandbox Code Playgroud)
并更改复选框以具有Property="myprop"属性。
<Property>在burn主题中添加任何元素似乎都会破坏它(.exe在构建后将不会运行)。
我遇到过以下代码:
var process = new Process
{
StartInfo =
{
Arguments = arguments,
FileName = applicationPath,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
Run Code Online (Sandbox Code Playgroud)
我觉得很困惑:为什么你能够省略 Process 之后的 () ?我假设这只是实例化进程对象,并在其上设置 StartInfo,但我不知道您可以使用这种语法。
MSDN 以传统语法显示了类似的内容:
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Run Code Online (Sandbox Code Playgroud)