我有一个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等价物,它不是我想要的.
在Sublime Text中,我经常使用Cmd+ P/ Ctrl+ P来搜索和跳转文件.
通常,它会选择临时或缓存的文件,如.scssc或/ tmp文件夹中的内容.
有没有办法可以限制搜索结果中显示的内容?
行为[MaxLength]和[StringLength]属性有什么区别?
据我所知(除了[MaxLength]可以验证数组的最大长度)这些是相同的,有点多余?
我可以使用什么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) 每当我提交表单时我都会收到此错误,因为这样就没有调用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
<%@ …Run Code Online (Sandbox Code Playgroud) 我正在阅读有关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) 我有在我使用的数据操作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) 如何将列值从转换varbinary(max)到varchar人类可读的形式?
我有一个C#webforms应用程序,直到今天才一直在游泳.
现在,突然间,每次我尝试运行应用程序时,都会出现文件锁定错误:
无法将文件"obj\Debug\MyProject.exe"复制到"bin\Debug\MyProject.exe".该进程无法访问文件"bin\Debug\MyProject.exe",因为它正由另一个进程使用.
谷歌搜索错误没有提出超出明显的任何东西,即VS认为文件被锁定.它肯定是Visual Studio本身锁定文件,因为当我关闭VS并重新打开它时,项目执行正常 - 第一次.当我第二次尝试运行它时,我收到文件锁定错误.
每次我想运行应用程序时关闭VS并重新打开都不是一个可行的解决方法!如何找出锁定文件的内容,并阻止其被锁定?
编辑:另一个有趣的发现:我甚至不必运行该应用程序.只需编译一次就会导致文件锁定; 我不能连续两次编译!
此问题特定于我的解决方案中的一个项目.所有其他项目都可以正常工作,并且可以根据需要执行多次.只有这一个项目才会被锁定.
我正在使用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)
我已经在另一个具有相同环境的应用程序中以这种方式工作而没有问题,但在这里我遇到了这个问题.我该怎么做才能解决这个问题?
c# ×3
.net ×1
arrays ×1
asp.net ×1
asp.net-mvc ×1
exception ×1
java ×1
java-8 ×1
java-stream ×1
linq ×1
peek ×1
sql ×1
sql-server ×1
sublimetext ×1
sublimetext2 ×1
t-sql ×1
vb.net ×1
winforms ×1
xml ×1
xpath ×1
xslt ×1