我正在使用C#输出文件,并希望通过添加括号和数字来处理使用相同名称保存的文件:
FooBar.xml
FooBar(1).xml
FooBar(2).xml
...
FooBar(N).xml
Run Code Online (Sandbox Code Playgroud)
在.NET中有一种简单的方法吗?这个(#)结构有一个特殊的名字吗?
我在.NET平台上使用Xunit和NMock.我正在测试一个方法是异步的表示模型.该方法创建一个异步任务并执行它,以便该方法立即返回,我需要检查的状态尚未准备好.
我可以在完成时设置一个标志而不修改SUT但这意味着我必须继续检查while循环中的标志,例如,可能超时.
我有什么选择?
此代码位于UITableViewController子类viewDidLoad方法中.UITableViewController子类包含一个测试方法.
它崩溃而没有抛出异常.
id dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"some text", @"text", @selector(test), @"selector", nil]
Run Code Online (Sandbox Code Playgroud) 我试图让以下代码编译,但在VS2008中遇到错误.谁能告诉我哪里出错了?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dummy
{
public class NaturalNumbersSequence : IEnumerable<int>
{
public IEnumerator<int> GetEnumerator()
{
for (int i = 1; i <= 1000; i++)
yield return i;
}
IEnumerator IEnumerable.GetEnumerator()
{
for (int i = 1; i <= 1000; i++)
yield return i;
}
}
class Program
{
static void Main(string[] args)
{
foreach (int i in new NaturalNumbersSequence())
Console.WriteLine(i);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我一直认为.NET中的根命名空间System主要用于那些不依赖于特定平台的东西.
我想知道如果任何人有任何意见或见解,为什么Windows.Forms命名空间中System,而不是Microsoft因为它似乎在一个平台上相当根深蒂固.
(如果可能的话,请不要进行火焰战争或不必要的MS抨击!:))
我正在尝试将.csproj文件设置为具有条件项组,该组将删除<ProjectReference>项组中的所有元素.
例如:
<ItemGroup>
<ProjectReference Include="..\..\..\..\Projects\Registrar\Ucsb.Sa.Registrar.Common\Ucsb.Sa.Registrar.Common\Ucsb.Sa.Registrar.Common.csproj">
<Project>{1EDDDE57-0181-41B4-B2AE-FB76450F85C8}</Project>
<Name>Ucsb.Sa.Registrar.Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="$(OnBuildServer) == 'true'">
<ProjectReference Remove="*" />
</ItemGroup>
<ItemGroup Condition="$(OnBuildServer) == 'true'">
<Reference Include="Ucsb.Sa.Registrar.Common">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(RegCommonDll)</HintPath>
</Reference>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
但是,当我将项目加载到VS 2008时,我收到错误消息'属性'删除元素<ProjectReference>中的"无法识别".奇怪的是删除属性在架构中(C:\ Program Files\Microsoft Visual Studio 9.0\Xml\Schemas\1033\MSBuild\Microsoft.Build.Core.xsd).上面有MSDN文档(http://msdn.microsoft.com/en-us/library/bb651786.aspx).并且,在MSDN文章"MSBuild Items"的底部有一个关于它的评论.
.csproj文件似乎指向.NET 3.5; 但我无法验证是否正在使用该版本的msbuild加载项目(有人知道该怎么做吗?)
.csproj文件的第一行:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Run Code Online (Sandbox Code Playgroud)
PS.我有了使用Build with msbuild的条件并动态设置项目引用的想法
我正试图让一个计时器在winform中每秒钟打一次,当我寻找关于如何做到这一点的建议我找到了大量关于线程的东西.好吧,我不关心线程,因为我所要做的就是让值在一分钟内从60倒数到0,然后停止.我认为我们不需要进入云计算来解决这个问题,但我真的是一个网络形式,所以我在这个问题上有点生疏.任何人都可以给我一个例子
这是我尝试过的
private void button1_Click(object sender, EventArgs e)
{
this.timeLeft = 60;
this.label1.Visible = false;
this.button1.Visible = false;
gt = new Timer();
gt.Tick += new EventHandler(CountDown);
gt.Interval = 1000;
gt.Start();
}
private void CountDown(object sender, EventArgs e)
{
do
{
this.TimeBar.Value = timeLeft;
this.timeLeft -= 1;
} while (this.timeLeft > 0);
if (this.TimeBar.Value > 0) return;
gt.Stop();
this.label1.Visible = true;
this.button1.Visible = true;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
在此XML中更新XElement(更新元素Pen的itemNumber值)的最佳方法是什么?
<?xml version="1.0" encoding="utf-8"?>
<MyStore>
<Category>
<itemName>Pen</itemName>
<itemNumber>12</itemNumber>
</Category>
<Category>
<itemName>Paper</itemName>
<itemNumber>23</itemNumber>
</Category>
</MyStore>
Run Code Online (Sandbox Code Playgroud) 如何暂停R脚本达指定的秒数或毫秒数?在许多语言中,都有一个sleep函数,但?sleep引用了一个数据集.而?pause和?wait不存在.
预期目的是用于自定时动画.所需的解决方案无需用户输入即可运行.
我在IE中输入[文本]字段的宽度有问题,所有版本.
我有一个明确设置宽度为250px的div.在这个div中,我有一个宽度设置为100%的输入文本字段.此输入还具有10px的内部左填充.
在IE中,它将宽度渲染为100%+ 10px.我无法找到一种限制容器宽度的技术.
此问题最初发生在所有浏览器中,但通过添加max-width:100%,很容易在FF,Safari和Chrome中修复.IE6/7不支持这一点,虽然IE8可以,但它仍然将填充添加到宽度.
据我所知,IE的盒子模型在宽度计算中包含了边框和边距,所以根据理解,我仍然无法找到解决方法.
我也试图找到一个更好的解决方案,而不仅仅是使用填充设置我的输入宽度为240px,因为这种形式有各种输入,容器的大小不同,我想找到一个通用的解决方案.
这是一些代码:
<div class="places_edit_left">
<h4>PHONE <strong>(NOT USER EDITABLE)</strong></h4>
<input type="text" value="" name="phoneNumber"/>
<h4>ADDRESS<strong>(NOT USER EDITABLE)</strong></h4>
<input type="text" value="" name="address"/>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.places_edit_left{ width:250px; }
.places_edit_left input{ width:100%; max-width:100%; padding-left:10px;}
Run Code Online (Sandbox Code Playgroud) .net ×4
c# ×3
winforms ×2
animation ×1
css ×1
file ×1
file-io ×1
ienumerable ×1
input ×1
msbuild ×1
namespaces ×1
nmock ×1
objective-c ×1
r ×1
statistics ×1
timer ×1
unit-testing ×1
width ×1
xml ×1
xunit.net ×1