我想从CSV文件创build一个数组。 这是简单的,你可以想象,CSV文件将只有一行和这些值: Device, SignalStrength, Location, Time, Age. 我想把这些值放入一维数组中。 我已经尝试过一些例子,但是它们都比所需要的更复杂。
我想在我最新的C#应用程序中通过契约来尝试一些小devise,并且想要类似于以下的语法: public string Foo() { set { Assert.IsNotNull(value); Assert.IsTrue(value.Contains("bar")); _foo = value; } } 我知道我可以从unit testing框架中获得这样的静态方法,但是我想知道这样的东西是否已经embedded到语言中,或者是否已经有某种框架在浮动。 我可以写我自己的断言function,只是不想重新发明轮子。
我在C ++中使用time.h来测量函数的时间。 clock_t t = clock(); someFunction(); printf("\nTime taken: %.4fs\n", (float)(clock() – t)/CLOCKS_PER_SEC); 不过,我总是把时间拿到0.0000。 时钟()和t分别打印时,具有相同的值。 我想知道是否有方法在C ++中精确地测量时间(可能是以纳秒为单位)。 我正在使用VS2010。
我有一个小的WPF应用程序,用于编译就好,但现在不是了。 我不能说它停止build设的时候。 它有一天工作得很好,接下来不是。 这是项目结构: 除了标准的.net dll之外,没有其他项目或外部参考。 下面是用户控制问题的起源: <UserControl x:Class="TimeRecorder.HistoryUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:TimeRecorder.ViewModel" xmlns:framework="clr-namespace:TimeRecorder.Framework" mc:Ignorable="d" Height="Auto" Width="Auto" Padding="5"> <UserControl.Resources> <local:HistoryViewModel x:Key="ViewModel"/> <framework:BoolToColorConverter x:Key="ColorConverter"/> </UserControl.Resources> <StackPanel DataContext="{StaticResource ViewModel}"> 这里是我得到的错误: 请注意,这不仅仅是截图中的一个文件,而是我在本项目的所有用户控件/窗口文件中以xaml类似的方式添加的所有引用。 所以文件就在那里,文件中的命名空间是正确的,xaml文件中的命名空间/类名是(据我了解)是正确的。 当我inputxaml时,我得到了intellisense,所以它find的文件确定,但不是编译时。 在其他post中最常见的解决scheme是.NET框架版本。 目前,我的主要和testing项目都设置为.Net Framework 4。 完整版本不是客户端configuration文件。 这是我想我搞砸了:在configurationpipe理器,这两个项目的平台设置为任何CPU,但有一次,当试图解决这个问题我注意到,主项目设置为x86和testing项目设置为任何中央处理器。 所以我在configurationpipe理器中为主项目手动添加了Any CPU。 但是,我真的不知道我是否正确地做了这件事,即使我应该这样做。 所以作为一个额外的问题,有没有办法可以将configurationpipe理器重置为默认状态? 这有什么要说的主要问题? 我不知道如果主项目总是设置为x86或不知道如果我改变它到x86然后它打破。 如上所述,这个项目正在编译一段时间。 有什么build议么? 我会回答更详细的代码或任何问题,而不是在这里散漫:)
我听到一个说c ++程序员应该避免memset, class ArrInit { //! int a[1024] = { 0 }; int a[1024]; public: ArrInit() { memset(a, 0, 1024 * sizeof(int)); } }; 所以考虑上面的代码,如果你不使用memset,你怎么能做一个[1..1024]填零?memset在C ++中有什么错误? 谢谢。
有没有办法做一个快速和肮脏的3D距离检查结果是粗糙的,但它是非常非常快? 我需要做深度分类。 我使用STL sort如下: bool sortfunc(CBox* a, CBox* b) { return a->Get3dDistance(Player.center,a->center) < b->Get3dDistance(Player.center,b->center); } float CBox::Get3dDistance( Vec3 c1, Vec3 c2 ) { //(Dx*Dx+Dy*Dy+Dz*Dz)^.5 float dx = c2.x – c1.x; float dy = c2.y – c1.y; float dz = c2.z – c1.z; return sqrt((float)(dx * dx + dy * dy + dz * dz)); } […]
可能重复: 首先拆分,然后join一个string的子集 我试图将一个string拆分成一个数组,取出第一个元素(使用它),然后将其余的数组join到一个单独的string中。 例: theString = "Some Very Large String Here" 会成为: theArray = [ "Some", "Very", "Large", "String", "Here" ] 然后我想在variables中设置第一个元素,稍后再使用它。 然后我想把数组的其余部分join到一个新的string中。 所以会变成: firstElem = "Some"; restOfArray = "Very Large String Here" 我知道我可以使用theArray[0]作为第一个元素,但是如何将数组的其余部分形成一个新的string呢?
我知道有几个人问了类似的问题,但是我找不到任何会让我明白为什么慢的问题。 所以,为了自己理解Visual Studio 2013中的线程对象,我制作了一个控制台程序。我的CPU是Intel Core i7,可以使用multithreading。 我的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Diagnostics; namespace ConsoleApplication1 { class Program { static TimeSpan MTTime; static TimeSpan STTime; static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Console.WriteLine(Environment.NewLine + "—————Multi Process————-" + Environment.NewLine); Thread th1 = new Thread(new […]
有没有办法缩短这个if语句的条件? int x; if (x != 3 && x != 8 && x != 87 && x != 9){ SomeStuff(); } 我在想这样的事情: if (x != 3, 8, 87, 9) {} 但是我试过了,不行。 我只需要长时间写下这些东西吗?
当试图达到所有绿色,我收到了Resharper以下build议。 原始码: static public string ToNonNullString(this XmlAttribute attr) { if (attr != null) return attr.Value; else return string.Empty; } build议:删除多余的“其他”导致以下内容: static public string ToNonNullString(this XmlAttribute attr) { if (attr != null) return attr.Value; return string.Empty; } 对我来说,build议的版本似乎不如原来的可读性。 Resharper的build议是否反映了良好可维护代码的定义?