小编Mik*_*iar的帖子

从现有阵列获取子阵列

我有一个10个元素的数组X. 我想创建一个新的数组,其中包含X中从索引3开始并以索引7结束的所有元素.当然,我可以轻松编写一个循环来为我做这个但我想保持我的代码尽可能干净.C#中有一种方法可以帮我吗?

像(伪代码)的东西:

Array NewArray = oldArray.createNewArrayFromRange(int BeginIndex , int EndIndex)
Run Code Online (Sandbox Code Playgroud)

Array.Copy不符合我的需要.我需要新数组中的项目是克隆.Array.copy只是一个C风格的memcpy等价物,它不是我想要的.

.net c# arrays

314
推荐指数
10
解决办法
38万
查看次数

在Sublime Text 2中限制文件搜索范围

在Sublime Text中,我经常使用Cmd+ P/ Ctrl+ P来搜索和跳转文件.

通常,它会选择临时或缓存的文件,如.scssc或/ tmp文件夹中的内容.

有没有办法可以限制搜索结果中显示的内容?

sublimetext sublimetext2

236
推荐指数
8
解决办法
6万
查看次数

StringLength vs MaxLength将ASP.NET MVC与Entity Framework EF Code First相关联

行为[MaxLength][StringLength]属性有什么区别?

据我所知(除了[MaxLength]可以验证数组的最大长度)这些是相同的,有点多余?

ef-code-first entity-framework-4.1 asp.net-mvc-3

144
推荐指数
6
解决办法
10万
查看次数

具有多个条件的XPath

我可以使用什么XPath来选择具有指定名称属性的任何类别以及具有指定值的任何子节点作者.

我尝试过以下路径的不同变体而没有成功:

//quotes/category[@name='Sport' and author="James Small"]
Run Code Online (Sandbox Code Playgroud)

XML:

<?xml version="1.0" encoding="utf-8"?>
<quotes>
  <category name="Sport">
   <author>James Small<quote date="09/02/1985">Quote One</quote><quote             date="11/02/1925">Quote nine</quote></author>
  </category>
   <category name="Music">
   <author>Stephen Swann
 <quote date="04/08/1972">Quote eleven</quote></author>
  </category>
  </quotes>
Run Code Online (Sandbox Code Playgroud)

xml xslt xpath

138
推荐指数
4
解决办法
23万
查看次数

已添加具有相同键的项目

每当我提交表单时我都会收到此错误,因为这样就没有调用action方法:

已添加具有相同键的项目.

和例外细节:

[ArgumentException:已经添加了具有相同键的项.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)+52
System.Collections.Generic.Dictionary`2.Insert(TKey key,TValue value,Boolean add)+9382923 System .Linq.Enumerable.ToDictionary(IEnumerable`1 source,Func`2 keySelector,Func`2 elementSelector,IEqualityComparer`1 comparer)+252
System.Linq.Enumerable.ToDictionary(IEnumerable`1 source,Func`2 keySelector,IEqualityComparer`1比较器)91
System.Web.Mvc.ModelBindingContext.get_PropertyMetadata()228 System.Web.Mvc.DefaultModelBinder.BindProperty(controllerContext controllerContext,ModelBindingContext的BindingContext,的PropertyDescriptor的PropertyDescriptor)392个
System.Web.Mvc.DefaultModelBinder.BindProperties(controllerContext controllerContext ,ModelBindingContext bindingContext)+147
System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext,ModelBindingContext bindingContext,Object model)+98
System.W eb.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext,ModelBindingContext bindingContext)+2504
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext,ModelBindingContext bindingContext)+548
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext,ParameterDescriptor parameterDescriptor) +473
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext,ActionDescriptor actionDescriptor)+181
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String actionName)+830 System.Web.Mvc.Controller.ExecuteCore()+ 136 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)+111
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)+39
System.Web.Mvc.<> c__DisplayClass8.b__4 ()+65 System.Web.Mvc.Async.<> c__DisplayClass1.b__0()+44 System.Web.Mvc.Async.<> c__DisplayClass8`1.b__7(IAsync 结果_)+42 System.Web.Mvc.Async.WrappedAsyncResult`1.End()+ 141 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+54
System.Web.Mvc.Async. AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+52
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)+38
System. Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+8836913 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+184

的ViewPage

<%@ …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

130
推荐指数
6
解决办法
32万
查看次数

在Java流中,窥视真的只用于调试吗?

我正在阅读有关Java流和发现新事物的内容.我发现的新事物之一是peek()功能.几乎所有我读过的内容都说它应该用来调试你的Streams.

如果我有一个Stream,每个帐户都有一个用户名,密码字段以及login()和loggedIn()方法,该怎么办?

我也有

Consumer<Account> login = account -> account.login();
Run Code Online (Sandbox Code Playgroud)

Predicate<Account> loggedIn = account -> account.loggedIn();
Run Code Online (Sandbox Code Playgroud)

为什么会这么糟糕?

List<Account> accounts; //assume it's been setup
List<Account> loggedInAccount = 
accounts.stream()
    .peek(login)
    .filter(loggedIn)
    .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

现在据我所知,这完全符合它的目的.它;

  • 获取帐户列表
  • 尝试登录每个帐户
  • 过滤掉任何未登录的帐户
  • 将登录的帐户收集到新列表中

做这样的事情的缺点是什么?有什么理由我不应该继续吗?最后,如果不是这个解决方案呢?

其原始版本使用.filter()方法如下;

.filter(account -> {
        account.login();
        return account.loggedIn();
    })
Run Code Online (Sandbox Code Playgroud)

java peek java-8 java-stream

115
推荐指数
7
解决办法
4万
查看次数

Sequence不包含匹配元素

我有在我使用的数据操作LINQ的asp.net应用程序.运行时,我得到异常"序列不包含匹配元素".

if (_lstAcl.Documents.Count > 0)
{
    for (i = 0; i <= _lstAcl.Documents.Count - 1; i++)
    {
        string id = _lstAcl.Documents[i].ID.ToString();                           
        var documentRow = _dsACL.Documents.First(o => o.ID == id);
        if (documentRow !=null)
        {

            _lstAcl.Documents[i].Read = documentRow.Read;
            _lstAcl.Documents[i].ReadRule = documentRow.ReadRule;

            _lstAcl.Documents[i].Create= documentRow.Create;
            _lstAcl.Documents[i].CreateRule = documentRow.CreateRule;

            _lstAcl.Documents[i].Update = documentRow.Update;
            _lstAcl.Documents[i].UpdateRule = documentRow.UpdateRule;

            _lstAcl.Documents[i].Delete = documentRow.Delete;
            _lstAcl.Documents[i].DeleteRule = documentRow.DeleteRule;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# linq exception

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

varbinary到SQL Server上的字符串

如何将列值从转换varbinary(max)varchar人类可读的形式?

sql t-sql sql-server sql-server-2005

87
推荐指数
5
解决办法
22万
查看次数

构建错误:"进程无法访问该文件,因为它正由另一个进程使用"

我有一个C#webforms应用程序,直到今天才一直在游泳.

现在,突然间,每次我尝试运行应用程序时,都会出现文件锁定错误:

无法将文件"obj\Debug\MyProject.exe"复制到"bin\Debug\MyProject.exe".该进程无法访问文件"bin\Debug\MyProject.exe",因为它正由另一个进程使用.

谷歌搜索错误没有提出超出明显的任何东西,即VS认为文件被锁定.它肯定是Visual Studio本身锁定文件,因为当我关闭VS并重新打开它时,项目执行正常 - 第一次.当我第二次尝试运行它时,我收到文件锁定错误.

每次我想运行应用程序时关闭VS并重新打开都不是一个可行的解决方法!如何找出锁定文件的内容,并阻止其被锁定?

编辑:另一个有趣的发现:我甚至不必运行该应用程序.只需编译一次就会导致文件锁定; 我不能连续两次编译!

此问题特定于我的解决方案中的一个项目.所有其他项目都可以正常工作,并且可以根据需要执行多次.只有这一个项目才会被锁定.

c# visual-studio-2010 winforms

81
推荐指数
9
解决办法
10万
查看次数

事务管理器已禁用其对远程/网络事务的支持

我正在使用SQL Server和ASP.NET.我有以下功能:

            Using js = daoFactory.CreateJoinScope()
                Using tran = New Transactions.TransactionScope()
                    '...
                    tran.Complete()
                End Using
            End Using
Run Code Online (Sandbox Code Playgroud)

但是,例外情况' 事务管理器已禁用其对远程/网络事务的支持.'被抛出.

JoinScope的描述:

Public Class JoinScope
    Implements IJoinScope
    Implements IDisposable
    '...
End Class
Run Code Online (Sandbox Code Playgroud)

我已经在另一个具有相同环境的应用程序中以这种方式工作而没有问题,但在这里我遇到了这个问题.我该怎么做才能解决这个问题?

vb.net asp.net transactionscope

81
推荐指数
4
解决办法
12万
查看次数