我有几个不需要任何州的课程.从组织的角度来看,我想把它们放到层次结构中.
但似乎我无法为静态类声明继承.
像这样的东西:
public static class Base
{
}
public static class Inherited : Base
{
}
Run Code Online (Sandbox Code Playgroud)
不管用.
为什么语言的设计者会关闭这种可能性?
我们有一个每天运行的批处理作业,并将文件复制到拾取文件夹.我还想获取该文件的副本并将其放入具有文件名的存档文件夹中
yyyy-MM-dd.log
Run Code Online (Sandbox Code Playgroud)
在Windows批处理作业中执行此操作的最简单方法是什么?
我基本上是在寻找这个Unix命令的等价物:
cp source.log `date +%F`.log
Run Code Online (Sandbox Code Playgroud) 编辑
作为参考,这里是eric在评论中引用的博客文章
http://blogs.msdn.com/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx
弊
我想更多的好奇心,但C#规范Savants的一个...
为什么ForEach()子句在IQueryable/IEnumerable结果集上不起作用(或不可用)...
你必须首先转换你的结果ToList()或ToArray()大概是对C#迭代IEnumerables Vs的方式的技术限制.列表......是否与IEnumerables/IQuerable Collections的延迟执行有关.例如
var userAgentStrings = uasdc.UserAgentStrings
.Where<UserAgentString>(p => p.DeviceID == 0 &&
!p.UserAgentString1.Contains("msie"));
//WORKS
userAgentStrings.ToList().ForEach(uas => ProcessUserAgentString(uas));
//WORKS
Array.ForEach(userAgentStrings.ToArray(), uas => ProcessUserAgentString(uas));
//Doesn't WORK
userAgentStrings.ForEach(uas => ProcessUserAgentString(uas));
Run Code Online (Sandbox Code Playgroud) 有一段时间我会尝试使用LINQ.枚举集合并在我的代码中更改其某些属性的典型方法如下所示:
ATDataContext dc = new ATDataContext(Settings.connection_string);
int[] col = ListViewClass.getListViewSelectedPositionTags(listView);
try
{
foreach (var item in col)
{
var ctx = (from r in dc.MailingLists
where r.ID == item
select r).Single();
ctx.Excluded = 'Y';
ctx.ExcludedComments = reason;
}
dc.SubmitChanges();
}
Run Code Online (Sandbox Code Playgroud)
有一段时间有一个建议来做到这一点...似乎更聪明的方式:
var ctx = from r in dc.MailingLists
where col.Contains(r.ID)
select r;
foreach (var item in ctx)
{
item.Excluded = 'Y';
item.ExcludedComments = reason;
}
dc.SubmitChanges();
Run Code Online (Sandbox Code Playgroud)
Iit在很多层面上都很有意义,我喜欢这个解决方案.它比第一个更聪明,更快捷.
我已经在生产环境中使用了这个解决方案一段时间了.
几周后,我在搜索应用程序日志文件时看到了什么,并看到了这一点:
"传入的表格数据流(TDS)远程过程调用(RPC)协议流不正确.此RCP请求中提供的参数太多.最大值为2100."
LINQ to SQL转换where col.Contains(r.ID)
为IN
子句看起来像:
WHERE ID …
我有一个简单的WCF Web服务.它在我们的生产域中的默认网站上的IIS上托管.(当地地址:10.10.20.100)
默认情况下,此默认网站是在端口80上为"所有未分配的"IP设置的:但是,我注意到这导致WCF服务使用服务器本地DNS名称生成它的WSDL.即wsdl中的所有URI都是
http://myserver.subdomain.domain.com/.../...
Run Code Online (Sandbox Code Playgroud)
这并不好,因为我需要将此服务公开给那些不了解生产环境内部DNS的网站.此特定服务器没有外部DNS名称.只是一个外部IP地址......
我从"全部未分配" - >"10.10.20.100"更改IIS中的设置方面取得了一些成功
这会导致Service使用URI生成它的WSDL
http://10.10.20.100/.../...
Run Code Online (Sandbox Code Playgroud)
这适用于子域和其他子域中的其他计算机,但是我在这里被卡住了.服务器外部IP地址(1.2.3.4)通过某些NAT/PAT转换进行映射,因此未在服务器IP设置中明确设置(即它不在IP Config下显示)
因此,如果我从"所有未分配" - >"1.2.3.4"更改IIS默认网站IP地址,就像我对内部地址所做的那样,那么WCF服务就会回来......
错误的请求(无效的主机名)
如果我在内部IP地址上保留IIS配置,并尝试通过我得到的外部IP地址访问服务
No protocol binding matches the given address
'http://1.2.3.4/TestService/Service.svc'. Protocol bindings are
configured at the Site level in IIS or WAS configuration
Run Code Online (Sandbox Code Playgroud)
有没有办法让IIS/WCF使用未在服务器上显式配置的外部IP地址生成它的WSDL URI?
在我将WCF服务拉出窗外之前,有人帮助了我.
想知道这是否可行.
我们有一个第三方库,其中包含有关用户的标识信息......
与库的主要交互是通过一个键控字符串的HashTable,并返回该键的信息的Object Graph.
问题是,关键显然是区分大小写,但我们从用户浏览器获得的内容并不一定与案例相符...(我们经常将密钥完全小写)
我想知道是否可以针对哈希表进行不敏感密钥搜索.
例如
Hashtable ht = new Hashtable();
ht.Add("MyKey", "Details");
string result = ht["MyKey"];
string result = ht["MYKEY"];
string result = ht["mykey"];
Run Code Online (Sandbox Code Playgroud)
如果有机会我们可以向公司提交支持票以添加此功能,是否有支持此功能的任何其他DataStructures(即新的通用集合/词典)
最后,是否有可能覆盖System.String GetHashCode()方法,使所有大小写不变的字符串返回相同的哈希码...例如,我认为这是一个没有人,因为string
是密封的类
欢呼,如果有人有任何建议
我使用任务并行库,可量化和可重复的问题BlockingCollection<T>
,ConcurrentQueue<T>
与GetConsumingEnumerable
试图创建一个简单的管道.
简而言之,从一个线程向默认值BlockingCollection<T>
(引擎盖下依赖于a ConcurrentQueue<T>
)添加条目并不能保证它们会BlockingCollection<T>
从调用GetConsumingEnumerable()
Method的另一个线程中弹出.
我创建了一个非常简单的Winforms应用程序来重现/模拟它,它只是将整数打印到屏幕上.
Timer1
负责排队工作项...它使用一个被调用的并发字典,_tracker
以便它知道它已经添加到阻塞集合中的内容.Timer2
只记录两个BlockingCollection
&的计数状态_tracker
Paralell.ForEach
简单地遍历阻塞集合GetConsumingEnumerable()
并开始将它们打印到第二个列表框的按钮.Timer1
阻止将更多条目添加到阻止集合中.public partial class Form1 : Form
{
private int Counter = 0;
private BlockingCollection<int> _entries;
private ConcurrentDictionary<int, int> _tracker;
private CancellationTokenSource _tokenSource;
private TaskFactory _factory;
public Form1()
{
_entries = new BlockingCollection<int>();
_tracker = new ConcurrentDictionary<int, int>();
_tokenSource = new CancellationTokenSource();
_factory = new TaskFactory();
InitializeComponent(); …
Run Code Online (Sandbox Code Playgroud) 这里可能存在多个相关的问题.我正在尝试为我们的3个移动应用程序提供一个简单的版本号更新方案,该应用程序是通过单个xamarin解决方案构建的.
我正在寻找的是一种简单的方法,可以保持所有这些值彼此同步,而无需单独更新它们.
我当前的设置需要导航到4个不同的位置以手动同步版本号.
我有一个链接文件,其中包含AssemblyVersion和AssemblyFileVersion,它们由解决方案中的所有PCL和Platform项目共享,并带有以下信息.
[assembly: AssemblyVersion("2.1.1.*")]
[assembly: AssemblyFileVersion("2.1.1.0")]
Run Code Online (Sandbox Code Playgroud)
单独在android项目下,我必须手动更新版本名称和版本号(int)
Version Name: 2.1.1
Version Number: 2
Run Code Online (Sandbox Code Playgroud)
在iOS应用程序选项卡下,我还有2个字段需要填写.
Version Number: 2.1.1
Build Number: 0 //Not sure if I'm using this field correctly.
Run Code Online (Sandbox Code Playgroud)
在WMAppManifest属性对话框的"打包"选项卡上,我还必须提供版本号.
Version Number: 2.1.1.0
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用它时将实体框架问题置于底层 TableController
我创建了以下设置.
基本的TodoItem示例提供了一个新的Mobile Web API,它利用了EntityFramework,TableController和默认的EntityDomainManager
public class TodoItemController : TableController<TodoItem>
{
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
context = new MobileServiceContext();
context.Database.Log += LogToDebug;
DomainManager = new EntityDomainManager<TodoItem>(context, Request);
}
public IQueryable<TodoItem> GetAllTodoItems()
{
var q = Query();
return q;
}
Run Code Online (Sandbox Code Playgroud)一个vanilla Web API 2控制器.
public class TodoItemsWebController : ApiController
{
private MobileServiceContext db = new MobileServiceContext();
public TodoItemsWebController()
{
db.Database.Log += LogToDebug;
}
public IQueryable<TodoItem> GetTodoItems()
{
return db.TodoItems;
}
Run Code Online (Sandbox Code Playgroud)我tablecontroller
用细齿梳子完成了代码,深入研究了Query
方法,这只是通过DomainManager
添加 …
c# entity-framework odata azure-mobile-services asp.net-web-api2
在反映ILSpy的同时,我在Queue<T>.Enqueue(T item)
-method中找到了这行代码:
if (this._size == this._array.Length)
{
int num = (int)((long)this._array.Length * 200L / 100L);
if (num < this._array.Length + 4)
{
num = this._array.Length + 4;
}
this.SetCapacity(num);
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道为什么有人会这样做?我认为这是一种整数溢出检查,但为什么先乘以200L
然后除以100L
?
这可能是早期编译器的问题吗?
c# ×6
.net ×3
.net-3.5 ×3
batch-file ×1
cmd ×1
dictionary ×1
foreach ×1
hashtable ×1
iis ×1
inheritance ×1
lambda ×1
linq-to-sql ×1
odata ×1
static ×1
timestamp ×1
versioning ×1
wcf ×1
web-services ×1
windows ×1
wpf ×1
xamarin ×1