众所周知,我们可以创建一个EventHandler并向其添加N次方法.喜欢:
// Declare and EventHandler
public event EventHandler InternetConnectionAvailableEvent;
private void OnInternetConnectionAvailableEvent()
{
if (InternetConnectionAvailableEvent != null)
{
EventHandler handle = InternetConnectionAvailableEvent;
EventArgs e = EventArgs.Empty;
handle(this, e);
}
}
// IN OTHER CLASS WHERE I USE THE EVENT
// Set the method name to handle the event
monitorInternet.InternetConnectionAvailableEvent += HandleInternetConnectionEvent;
void HandleInternetConnectionEvent(object sender, EventArgs e)
{
if (syncContext != null)
{
MonitorInternetConnection mic = (MonitorInternetConnection)sender;
if (mic != null)
{
syncContext.Post(o => InternetConnected(), null);
}
}
}
// To …Run Code Online (Sandbox Code Playgroud) 我有一个类,它使用一个空接口作为"标记接口",如下所示:
namespace MyNameSpace
{
public interface IMessage
{
//nothing in common here...
}
public class MyMessage : IMessage
{
public void SendMyMessage()
{
//Do something here
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在其他一些帖子中读到了,但在MSDN(http://msdn.microsoft.com/en-us/library/ms182128.aspx)上也应该避免这种情况,你应该使用自定义属性而不是这个空接口.所以,我可以像这样重构我的代码:
namespace MyNameSpace
{
public class MessageAttribute : Attribute
{
//nothing in common here...
}
[MessageAttribute]
public class MyMessage
{
public void SendMyMessage()
{
//Do something here
}
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但主要问题是:
当我在程序的其他地方有一个通用方法时,例如:
public IEnumerable<T> GetAll<T>() where T : IMessage
{
//Return all IMessage things here
}
Run Code Online (Sandbox Code Playgroud)
在上面的函数中,我确实需要添加一些泛型类型约束T,因此只 …
在F#interactive中,如何查看此会话中定义的变量/函数列表?像whos()python或ls()R中的函数一样?谢谢.
我想将证书的指纹存储在如下变量中:
$thumbprint = 0F273F77B77E8F60A8B5B7AACD032FFECEF4776D
Run Code Online (Sandbox Code Playgroud)
但我的命令输出是:
Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Subject -match "XXXXXXX"}
Thumbprint Subject
---------- -------
0F273F77B77E8F60A8B5B7AACD032FFECEF4776D CN=XXXXXXX, OU=YYYYYYY
Run Code Online (Sandbox Code Playgroud)
我需要删除除输出的指纹之外的所有内容
任何的想法?
我最近开始在Java SE中编程,我从很多文章中听到并且从传闻中听到,Android应用程序是用Java开发的,或者用类似于Java的语言开发的.
我还注意到还有其他软件包可供使用,因为我们必须为移动设备开发.
直到最近,我从未对移动设备和应用程序感兴趣,例如Android操作系统,但现在我明白这是未来,并且很有可能找到工作.
我的问题是:如果在不久的将来,我想在Android中开发一些东西,我是否必须学习与现在编程不同的Java语言?
Android中使用的Java语言和Java之间是否存在许多差异(编程方式)?
谢谢.
我正在开发一个RMI命令行游戏但是,每当我尝试使用我的服务时,都会收到如下错误:
java.rmi.ConnectException: Connection refused to host: 192.168.56.1; nested exception is:
java.net.ConnectException: Connection timed out: connect
Run Code Online (Sandbox Code Playgroud)
这是我的主要课程Server:
public class RMIWar {
public static void main(String[] args) throws RemoteException, MalformedURLException {
try {
Controle obj = new Controle(4);
Registry reg = LocateRegistry.createRegistry(1099);
System.out.println("Server is ready");
reg.rebind("CtrlServ", obj);
}
catch (Exception e) {
System.out.println("Error: " + e.toString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
我Client班的主要内容:
public class RMIWarClient {
public static void main(String[] args) throws RemoteException, MalformedURLException, NotBoundException {
try {
Registry registry …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
var list = from c in child_categories orderby c.Translated_Syntax
select new { Name = c.Translated_Syntax, ID = c.ID_Category } ;
lst_category.DataSource = list;
lst_category.DataBind();
Run Code Online (Sandbox Code Playgroud)
我的分类列表是:汽车,其他,儿童,房子,女孩,显示.
如果我订购我的清单,结果将是:
但是我希望将"其他"项目放在列表的底部.像这样的东西:
我怎样才能做到这一点?
在我的网站上,我在创建视差时体验 - 还有很多其他人 - 在Internet Explorer 11(在Windows 8.1计算机上)上有一种跳跃/滞后效果.以Firefox为例,它工作得非常好.
根据我的研究,这是IE11的一个常见问题,没有解决方案,但我找到了一个网站以某种方式解决了这个问题(或者做了一个解决方法?!?):http: //focuslabllc.com/journal
但是我的网站和这个问题有同样的问题:http: //negativespacealphabet.com/ 他们为了让它工作有什么不同的做法?我感谢您的帮助!
我想在SQL Select中检索一个整数值,但仅在数据发生变化时,例如:
表数据:
50 50 50 52 50 30 30 35 30 30 60 65 60 60
Run Code Online (Sandbox Code Playgroud)
现在我想得到这些数据:
50 52 50 30 35 30 60 65 60
Run Code Online (Sandbox Code Playgroud)
执行一个不同的查询,这对我不起作用,因为它将检索:
50 52 30 35 60 65
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在使用Entity Framework和C#,因此使用它们的建议也将受到赞赏!
谢谢.
今天,我在迭代一系列项目时遇到了性能问题.在完成一些诊断之后,我终于找到了降低性能的原因.事实证明,迭代IEnumerable<T>一次比花费更多的时间List<T>.请帮我理解为什么IEnumerable<T>比慢List<T>.
UPDATE基准上下文:
我正在使用NHibernate从数据库中获取项目集合IEnumerable<T>并对其属性值进行求和.这只是一个没有任何引用类型的简单实体:
public SimpleEntity
{
public int Id {get;set}
public string Name {get;set}
public decimal Price {get;set}
}
Public Test
{
void Main()
{
//this query get a list of about 200 items
IEnumerable<SimpleEntity> entities = from entity in Session.Query<SimpleEntity>
select entity;
decimal value = 0.0;
foreach(SimpleEntity item in entities)
{
//this for loop took 1.5 seconds
value += item.Price;
}
List<SimpleEntity> lstEntities = entities.ToList();
foreach(SimpleEntity item in …Run Code Online (Sandbox Code Playgroud)