我有一个2字符串和1双(数量)的类.
班捐赠者
现在我已经填充了一系列捐款人.
我如何按金额排序?
我在.NET 1.1项目上工作了很长时间,我被困在C#1.0,现在我想赶上最新最好的.
Google在C#v2.0中返回了大量有关新功能的信息,但对于版本3和版本4,我只找到了部分信息.
互联网上是否存在某些列表,列出了在v2.0,v3.0和v4.0中引入的所有新功能?
如何获取打开的文件夹列表,通过它进行枚举并以编程方式最小化每个文件夹?
有时,一些打开的文件夹在从应用程序中的一个表单跳转到另一个表单时会从该工具中窃取焦点.防止这种情况对我们的客户来说是高度优先的.客户是视障人士,因此他们只能通过屏幕阅读器访问机器.最小化其他窗口(文件夹)根本不是问题,实际上是一个要求.
我试过这个:
foreach (Process p in Process.GetProcessesByName("explorer"))
{
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样没有好处.
更新:
从这里的答案,我试过这个:
delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
static IEnumerable<IntPtr> EnumerateProcessWindowHandles(int processID)
{
List<IntPtr> handles = new List<IntPtr>();
EnumThreadDelegate addWindowHandle = delegate(IntPtr hWnd, IntPtr param)
{
handles.Add(hWnd);
return true;
};
foreach (ProcessThread thread in Process.GetProcessById(processID).Threads)
EnumThreadWindows(thread.Id, addWindowHandle, IntPtr.Zero);
return handles;
}
const int SW_MINIMIZED = 6;
[DllImport("user32.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
private …
Run Code Online (Sandbox Code Playgroud) 代码:
string sURL = "http://subdomain.website.com/index.htm";
MessageBox.Show(new System.Uri(sURL).Host);
Run Code Online (Sandbox Code Playgroud)
给了我"subdomain.website.com"
但我需要主域名"website.com"用于任何网址或网站链接.
我怎么做?
我有一个BasePage类,所有其他页面派生自:
public class BasePage
Run Code Online (Sandbox Code Playgroud)
这个BasePage有一个构造函数,其中包含必须始终运行的代码:
public BasePage()
{
// Important code here
}
Run Code Online (Sandbox Code Playgroud)
我想强制派生类调用基础构造函数,如下所示:
public MyPage
: base()
{
// Page specific code here
}
Run Code Online (Sandbox Code Playgroud)
我该如何强制执行此操作(最好是在编译时)?
好的,所以我创建了我的c#应用程序,为它创建了一个安装程序,并在我的机器上安装了它.
问题是,当用户打开应用程序exe两次时,将运行两个应用程序实例.我只想要一个应用程序的一个实例随时运行,我该怎么做呢?
谢谢你的帮助,
我正在尝试阅读我编译的C#代码.
这是我的代码:
using(OleDbCommand insertCommand = new OleDbCommand("...", connection))
{
// do super stuff
}
Run Code Online (Sandbox Code Playgroud)
但!
我们都知道使用被转换为:
{
OleDbCommand insertCommand = new OleDbCommand("...", connection)
try
{
//do super stuff
}
finally
{
if(insertCommand != null)
((IDisposable)insertCommand).Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
(因为OleDbCommand是一个引用类型).
但是当我反编译我的程序集(用.NET 2.0编译)时,我在Resharper中得到了这个:
try
{
insertCommand = new OleDbCommand("", connection);
Label_0017:
try
{
//do super stuff
}
finally
{
Label_0111:
if ((insertCommand == null) != null)
{
goto Label_0122;
}
insertCommand.Dispose();
Label_0122:;
}
Run Code Online (Sandbox Code Playgroud)
我在说这句话:if ((insertCommand == null) != null)
.
假设insertCommand为null.然后第一部分返回true.(true …
我想有些人可能能够回答这个问题,这是一个出于好奇的问题:
.NET v2中引入的泛型CreateInstance
方法System.Activator
对泛型参数没有类型约束,但在激活类型上需要默认构造函数,否则MissingMethodException
抛出a.对我而言,这个方法似乎应该有类型约束
Activator.CreateInstance<T>() where T : new() {
...
}
Run Code Online (Sandbox Code Playgroud)
只是遗漏或潜伏在这里的一些轶事?
更新
正如所指出的,编译器不允许你编写
private T Create<T>() where T : struct, new()
error CS0451: The 'new()' constraint cannot be used with the 'struct' constraint
Run Code Online (Sandbox Code Playgroud)
但是,请参阅注释可以将结构用作指定new()约束的泛型方法的类型参数.在这种情况下,给定的答案似乎是不限制方法的唯一正当理由......
谢谢你看看这个!
这个让我困惑了一下......试图处理一个XmlReader
XmlReader reader = XmlReader.Create(filePath);
reader.Dispose();
Run Code Online (Sandbox Code Playgroud)
提供以下错误:
由于其保护级别,'System.Xml.XmlReader.Dispose(bool)'无法访问
但是以下情况很好:
using(XmlReader reader = XmlReader.Create(filePath))
{
}
Run Code Online (Sandbox Code Playgroud)
当我在Reflector中查看定义时,我无法理解为什么我不能调用Dispose
Dispose的实现:
任何人都可以指出我错过了什么?
我有一个问题,我必须在c#中应用屏蔽/隐藏电子邮件地址的一部分.例
jhon@abc.com==> jh**n@abc.com
bigjhon@abc.com==> bi****n@abc.com
brotherhood@abc.com==>br*******od@abc.com
Run Code Online (Sandbox Code Playgroud)
我有这个代码,但它给了一些电子邮件的例外."指数数组的边界之外."
for (int i = 0; i < eml.Length; i++)
{
int j = i == (eml.Length - 1) ? 0 : 1;
cc = eml[i].ToString();
if (i <= 1)
{
dispeml += cc;
}
else
if (eml[i + (j + k)].ToString() == "@")
{
dispeml += cc;
k = 0;
fl = 1;
}
else
if (eml[i + j].ToString() == "@")
{
dispeml += cc;
fl = 1;
}
else
if (fl == …
Run Code Online (Sandbox Code Playgroud)