小编LB.*_*LB.的帖子

将参数传递给模板化类型的C#generic new()

我正在尝试在添加到列表时通过其构造函数创建类型为T的新对象.

我收到编译错误:错误消息是:

'T':创建变量实例时无法提供参数

但我的类确实有一个构造函数参数!我怎样才能做到这一点?

public static string GetAllItems<T>(...) where T : new()
{
   ...
   List<T> tabListItems = new List<T>();
   foreach (ListItem listItem in listCollection) 
   {
       tabListItems.Add(new T(listItem)); // error here.
   } 
   ...
}
Run Code Online (Sandbox Code Playgroud)

.net c# generics new-operator

395
推荐指数
10
解决办法
19万
查看次数


x:Key和x:WPF中的名称有什么区别?

WPF x:Keyx:NameWPF 之间的区别是什么?

我不确定真正的区别是什么.

wpf

52
推荐指数
2
解决办法
2万
查看次数

请求JavaScript地址

可能重复:
使用JavaScript获取当前URL?

你如何在JavaScript中获得你所在页面的地址?

例如,如果我有一个脚本,somesite.com/javascript/home.html我想找到请求地址(somesite.com/javascript/home.html),我如何在JavaScript中获取此信息?

javascript

51
推荐指数
3
解决办法
2万
查看次数

iOS应用版本控制

在iOS中,有什么区别:

Bundle版本字符串,短AND Bundle版本?

在构建新版本时何时更新?

在此输入图像描述

iphone ipad ios4 ios

21
推荐指数
1
解决办法
1万
查看次数

POST请求(Javascript)

如何在不使用表单且不回发的情况下在Javascript中创建简单的POST请求?

html javascript post

20
推荐指数
3
解决办法
8万
查看次数

window.location.href vs点击一个Anchor

点击之间有什么区别:

<a href />
Run Code Online (Sandbox Code Playgroud)

调用 window.location.href = ...

javascript

18
推荐指数
2
解决办法
2万
查看次数

IP端点0.0.0.0:13000上已有一个侦听器.?? (TCP使用WCF)

我试图弄清楚为什么即使在重新启动计算机后仍在使用端口!

System.ServiceModel.AddressAlreadyInUseException:IP端点0.0.0.0:13000上已有一个侦听器.如果有另一个应用程序已在此端点上侦听,或者如果服务主机中有多个服务端点具有相同的IP端点但具有不兼容的绑定配置,则可能会发生这种情况.---> System.Net.Sockets.SocketException:System的System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,SocketAddress socketAddress)通常只允许使用每个套接字地址(协议/网络地址/端口). Net.Sockets.Socket.Bind(端点localEP)在System.ServiceModel.Channels.SocketConnectionListener.Listen()---内部异常堆栈跟踪的末尾在System.ServiceModel.Channels.SocketConnectionListener.Listen()在系统. ServiceModel.Channels.TracingConnectionListener.Listen()在System.ServiceModel.Channels.ConnectionAcceptor.StartAccepting()在System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()在System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)的系统. ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)在System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(时间跨度超时)在System.ServiceModel.Channels.Communicat ionObject.Open在System.ServiceModel.Channels.CommunicationObject.Open(时间跨度超时)在System.ServiceModel.ServiceHostBase.OnOpen(时间跨度超时)在系统(时间跨度超时)在System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(时间跨度超时). ServiceModel.Channels.CommunicationObject.Open(时间跨度超时)在Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo信息)System.Net.Sockets.SocketException(0X80004005):每个套接字地址中的一个使用量(协议/网络地址/端口)在System.Net.Sockets.Socket.DoBind(端点endPointSnapshot,为SocketAddress的SocketAddress)在System.Net.Sockets.Socket.Bind(端点localEP)在System.ServiceModel.Channels.SocketConnectionListener.Listen正常允许()

你怎么知道哪个进程正在侦听该端口(13000)?Netstat在该端口上没有显示任何内容.

这是我的App.config:

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="SomeTarget.SomeTargetService">
        <endpoint address="" binding="customBinding" bindingConfiguration="NetTcpBinding"
          contract="SomeTarget.ISomeTargetService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:13000" />
          </baseAddresses>
        </host>
      </service>
    </services>

    <bindings> …
Run Code Online (Sandbox Code Playgroud)

.net c# windows wcf tcp

17
推荐指数
4
解决办法
3万
查看次数

从Array转换为ICollection <T>

在C#中实现这一目标的最佳方法是什么?

c#

15
推荐指数
2
解决办法
1万
查看次数

中风和填充之间的区别?

图形上下文中的笔画和填充绘图之间有什么区别(iPhone SDK)

core-graphics iphone-sdk-3.0

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×3

javascript ×3

.net ×2

c ×1

const ×1

core-graphics ×1

generics ×1

html ×1

ios ×1

ios4 ×1

ipad ×1

iphone ×1

iphone-sdk-3.0 ×1

new-operator ×1

pointers ×1

post ×1

tcp ×1

wcf ×1

windows ×1

wpf ×1