小编sha*_*oni的帖子

两个函数之间经过的时间

我需要找到两个函数执行相同操作但用不同算法编写的时间.我需要找到两者中最快的

这是我的代码片段

Stopwatch sw = new Stopwatch();
sw.Start();
Console.WriteLine(sample.palindrome()); // algorithm 1
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);//tried sw.elapsed and sw.elapsedticks
sw.Reset(); //tried with and without reset
sw.Start();
Console.WriteLine(sample.isPalindrome()); //algorithm 2
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Run Code Online (Sandbox Code Playgroud)

从技术上讲,这应该给两个算法花费的时间.这使得算法2更快.但是如果我交换两个函数的调用,它会给出不同的时间.就像我先调用algorithm2而第二次调用algorithm1一样,它表示algorithm1更快.

我不知道我做错了什么.

c# algorithm time

19
推荐指数
2
解决办法
1395
查看次数

将事件侦听器添加到附加在 d3 中的 <div>

我正在尝试将事件(addeventlistner)添加到附加有 d3 的多个元素。但是,当我单击 时,它不会触发附加的“警报”。有趣的是,这适用于<div>我手动添加的内容。有人可以摆脱吗对此有何看法?

d3.csv("output1.csv",function(data){    
var width = 700,
    height = 600;   
d3.select('body').selectAll("div")
    .data(data)
    .enter()
    .append("div")
    .style("width",30)
    .style('height',30)
    .style("background-color",function(d){
        return d.color;
}) 
var divs = document.getElementsByTagName("div") // this returns array of div elements    
function show(){
        alert("ya")
    }   
for (var i = 0; i < divs.length; i++) {
            divs[i].addEventListener('click',function(){
        alert("yaho")
    })
  } 
})
Run Code Online (Sandbox Code Playgroud)

javascript events addeventlistener d3.js

5
推荐指数
1
解决办法
3906
查看次数

在asp.net中的图表控件中绘制条形图和折线图

<asp:Chart ID="chartSellThru" runat="server" Height="400px" Width="1200px" >
    <Series>                       
        <asp:Series Name="ActualsQTD">
        </asp:Series>
        <asp:Series Name="ForecastQTD">
        </asp:Series>
        <asp:Series Name="QTDRatio" ChartType="Line">
        </asp:Series>
        <asp:Series Name="TargetAttain" ChartType="Line">
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="SellThruChartArea">
        </asp:ChartArea>
    </ChartAreas>

chartSellThru.Series["ActualsQTD"].XValueMember = "ProductGroup";
chartSellThru.Series["ActualsQTD"].YValueMembers = "ActualsQTD";
Run Code Online (Sandbox Code Playgroud)

我在default.aspx页面上写了上面的代码行,最后两行代码写在default.aspx.cs页面中.数据绑定到图表.

如何编写折线图的代码.确保从database.how绑定值以将值从sql server绑定到折线图.

c# asp.net

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

获取没有扩展名的文件名

这是我获取带有扩展名的Uploaded Filename和仅获取扩展名的语法

$name = Input::file('photo')->getClientOriginalName();
$extension = Input::file('photo')->getClientOriginalExtension();
Run Code Online (Sandbox Code Playgroud)

如果我上传一个名为的文件,那么file.jpg我会得到

$name = file.jpg
$extension = jpg
Run Code Online (Sandbox Code Playgroud)

是否有任何预定义的方式来获取文件名,即file不使用任何字符串替换.如果不善意建议一种方法来实现str替换或任何其他方式.

php file-upload laravel laravel-4

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

"params"和"array parameter"有什么区别?什么时候应该使用它?

这两种方法之间的确切区别是什么?何时使用"params"以及何时使用数组参数?回复将不胜感激.

// passing array to a method
class Program
{
    static void printarray(int[] newarray)
    {
        int i,sum=0;
        Console.Write("\n\nYou entered:\t");
        for (i = 0; i < 4; i++)
        {
            Console.Write("{0}\t", newarray[i]);
            sum = sum + newarray[i];
        }
        Console.Write("\n\nAnd sum of all value is:\t{0}", sum);
        Console.ReadLine();
    }
    static void Main(string[] args)
    {
        int[] arr = new int[4];
        int i;
        for (i = 0; i < 4; i++)
        {
            Console.Write("Enter number:\t");
            arr[i] = Convert.ToInt32(Console.ReadLine());
        }
        // passing array as argument
        Program.printarray(arr);
        }
    } …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
1871
查看次数

关于将com com端口字符串转换为整数数组

如果字符串是这样声明的,那么效果很好

String str="179,206";            
String [] numbers = str.split(",");            
int[] ints = new int[numbers.length];
for(int i = 0;i < numbers.length;i++)
{   
    ints[i] = Integer.parseInt(numbers[i]);
}
Run Code Online (Sandbox Code Playgroud)

我使用下面的代码读取相同的字符串fromm com port

serialPort.openPort();//Open serial port
serialPort.setParams(9600, 8, 1, 0);//Set params.
byte[] buffer = serialPort.readBytes(8);//Read 8 bytes from serial port
String str = new String(buffer);
Run Code Online (Sandbox Code Playgroud)

然后使用前面的代码转换为整数.然后它在线程"main"中给出以下错误Exception

java.lang.NumberFormatException

:对于输入字符串:"179",在java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)java.lang.Integer.parseInt(Integer.java:481)java.lang.Integer.parseInt(Integer.java:527)simpleread.SimpleRead.main(SimpleRead.java:44)

java string

2
推荐指数
1
解决办法
197
查看次数

如何在Kendo UI Grid中设置行背景颜色?

我有21行的网格.我的要求是设置一些行背景颜色是浅绿色(如1,5,13行)这是可能实现的.

$("#gridSellIn")
     .kendoGrid({
         width: 1500,
         dataSource: data.d,
         resizable: true,
         selectable: true,                                
         rowTemplate: kendo.template($("#SellInrowTemplate").html()),
                            height: 500,
                            columns: [
                                            { title: 'RevProduct Name', field: 'ProductName', width: '22%', sortable: true },
                                            { title: 'Actuals', field: 'Actual', width: '8%', sortable: true },

                                      ]
                        }); 
Run Code Online (Sandbox Code Playgroud)

jquery kendo-ui

1
推荐指数
3
解决办法
2万
查看次数