小编the*_*ist的帖子

当函数返回结果和JavaScript中的函数时

我看到很多函数返回的不是结果而是函数.下面的示例显示函数getWindow返回函数.为什么它不能只返回变量"赢"?当我返回结果和功能时?谢谢.

var A = function(){};
A.prototype=
{
   getWindow : function()
   {
        var win = new B.window();
        return (
                this.getWindow = function()
                {
                    return win;
                })();

   }
}
Run Code Online (Sandbox Code Playgroud)

javascript javascript-framework

7
推荐指数
1
解决办法
253
查看次数

为什么C#支持使用字符串切换而C++不支持?

可能重复:
为什么switch语句不能应用于字符串?

在一些帖子中,我读到原因是"编译器必须理解两个值相等意味着什么",但在C#中它也不知道并且只是调用函数类似Equals,那么为什么C++也不能这样做呢?

c# c++ switch-statement

7
推荐指数
0
解决办法
122
查看次数

如何使用StructureMap将相同的接口映射到不同的ConcreteClasses?

在创建Controller1时,我希望IService将映射到ConcreteService1,将IPageService映射到ConcretePageService1

当创建Controller2时,我希望IService将映射到ConcreteService2,IPageService将映射到ConcretePageService2

我如何初始化ObjectFactory以便以上工作?

这意味着我以这种方式初始化ObjectFactory:

 ObjectFactory.Initialize(x =>
    {  
         x.For<IService>().Use<ConcreteService1>();
         x.For<IPageService>().Use<ConcretePageService1>();
    });
Run Code Online (Sandbox Code Playgroud)

但是,这始终映射ConcreteService1到IService和ConcretePageService1到IPageService无论控制器类型

public class Controller1 : Controller
{
    public Controller1(IService service, IPageService pageService)
    {
    }
}

public class Controller2 : Controller
{
     public Controller2(IService service, IPageService pageService)            
     {         
     }
}

public interface IService 
{
}
public class ConcreteService1:IService 
{
}
public class ConcreteService2:IService 
{
}

public interface IPageService 
{
}
public class ConcretePageService1:IPageService 
{
}
public class ConcretePageService2:IPageService 
{
}
Run Code Online (Sandbox Code Playgroud)

c# structuremap

6
推荐指数
1
解决办法
3774
查看次数

为什么Response.Redirect与新的RedirectResult()之间存在差异?

当我像这样重定向

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
      filterContext.Result = new RedirectResult("https://mydom.com");
 }
Run Code Online (Sandbox Code Playgroud)

所以浏览器重定向到http://mydom.com/httpS://mydom.com

但如果我这样重定向

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
      var res = filterContext.HttpContext.Response;
      filterContext.Result = res.Redirect("https://mydom.com");
 }
Run Code Online (Sandbox Code Playgroud)

所以浏览器正确地重定向到https://mydom.com

为什么会有区别?

model-view-controller asp.net-mvc

6
推荐指数
1
解决办法
2496
查看次数

如何删除WP7中按钮周围的黑色空间?

正如我所见,WP7按钮被一些像素的黑色空间所包围.我怎么能删除它?

我已经阅读过这篇文章,但我没有设法删除它!你能举个实例吗?

我试图用<Border... />元素包装按钮,但它没有用.

这是我的XAML

<ItemsControl Name="icCells" Grid.Row="1">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Background="Red" BorderThickness="0"  Width="40" Height="40" BorderBrush="Green" Padding="0" Margin="0" />

                </DataTemplate>                   
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
Run Code Online (Sandbox Code Playgroud)

谢谢

silverlight-3.0 windows-phone-7 windows-phone-7.1

6
推荐指数
2
解决办法
6517
查看次数

在方法签名中使用新关键字通常只是为了提高可读性?

我已经阅读了方法签名中的new关键字,并且已经在这篇文章中看到过以下示例,但我仍然不明白为什么要在方法签名中编写new关键字.如果我们省略它,它仍然会做同样的事情.它会编译.会有一个警告,但它会编译.

那么,写new 方法签名只是为了可读性?

public class A
{
   public virtual void One() { /* ... */ }
   public void Two() { /* ... */ }
}

public class B : A
{
   public override void One() { /* ... */ }
   public new void Two() { /* ... */ }
}

B b = new B();
A a = b as A;

a.One(); // Calls implementation in B …
Run Code Online (Sandbox Code Playgroud)

c# c#-4.0

6
推荐指数
2
解决办法
1027
查看次数

在mp4容器中保存视频时FPS太高

当我从avi文件解码帧然后在x264中解码它们并保存到mp4文件时,输出文件的fps总是12,800.因此文件播放速度非常快.但是,当我以avi格式保存编码的h264帧而不是mp4时,所以fps就像我想要的那样--25.

可能是什么问题呢?

这里是我在VS2010中编写的代码:

#include "stdafx.h"
#include "inttypes.h"

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include <libswscale/swscale.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}

#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
   const char* inFileName = "C:\\000227_C1_GAME.avi";
   const char* outFileName = "c:\\test.avi";
   const char* outFileType = "avi";

   av_register_all();

   AVFormatContext* inContainer = NULL;   
   if(avformat_open_input(&inContainer, inFileName, NULL, NULL) < 0)   
      exit(1);

   if(avformat_find_stream_info(inContainer, NULL) < 0)
      exit(1);

   // Find video stream
   int videoStreamIndex = -1;
   for (unsigned int i …
Run Code Online (Sandbox Code Playgroud)

c++ mp4 ffmpeg libavcodec libx264

6
推荐指数
1
解决办法
3764
查看次数

在 MSTest 测试中使用具有 DynamicData 属性的结构时数据无效?

我使用 MSTest.Framework/MSTest.TestAdapter 2.2.10。

Test_Method我正在尝试使用属性传递测试数据DynamicData。当struct和我 debugMyDateTime时,的字段有错误的日期。但是,当我转到class,我得到了正确的日期。可能是什么问题?我的装箱/拆箱有问题吗?Test_Method_datetestDataMyDateTimeMyDateTime

[TestMethod]
[DynamicData(nameof(DataForTestMethod), DynamicDataSourceType.Property)]
public void Test_Method(MyDateTime testData)
{
}

public struct MyDateTime
{
    private DateTime _date;

    public MyDateTime(DateTime dt)
    {
        _date = dt;
    }
}

public static IEnumerable<object[]> DataForTestMethod
{
    get
    {
        var dt = new DateTime(2022,04,30,21,04,22);
        var myDate = new MyDateTime(dt);
        yield return new object[] { myDate };
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# unit-testing mstest

6
推荐指数
1
解决办法
457
查看次数

如何创建Entity Framework ObjectContext?

我在一个SQL服务器中有很多数据库.我将connectionString作为模板(看看Initial Catalog={0})放入web.config中.

<add name="ent" connectionString="metadata=res://*/ent.csdl|res://*/ent.ssdl|res://*/ent.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=1.1.1.1;Initial Catalog={0};Persist Security Info=True;User ID=user;Password=pass;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

我想用正确的connectionString创建objectContext.我想要做以下事情,CreatObjectContext<SiteEntities>('MySite')但我得到错误Unable to determine the provider name for connection of type 'System.Data.EntityClient.EntityConnection'.

public T CreatObjectContext<T>(string dbName) where T : ObjectContext, new()
{          
       var conStr = ConfigurationManager.ConnectionStrings["ent"].ConnectionString;
       var entityBuilder = new EntityConnectionStringBuilder(conStr);
       entityBuilder.Provider = "System.Data.SqlClient";
       // Build correct conString to the db
       entityBuilder.ProviderConnectionString = string.Format(entityBuilder.ProviderConnectionString, dbName);

       var connection = new EntityConnection(entityBuilder.ConnectionString);                          
       var builder = new ContextBuilder<T>();

       return builder.Create(connection);           
}
Run Code Online (Sandbox Code Playgroud)

我做错了什么?我如何创建上下文?

entity-framework entity-framework-4 objectcontext c#-4.0

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

在提交或回滚作用域之前,TransactionScope块中的所有代码如何才真正执行?

我读过有关的TransactionScope这个文章,但我还是不明白两两件事:

  1. 何时SqlCommand.ExecuteNonQuery执行它直到scope.Complete()被调用才真正执行?如果这是真的,那么范围内执行的所有操作都会保留并等待scope.Complete()scope.Rollback()
  2. 何时TransactionScope实例化它如何阻止SqlCommand.ExecuteNonQuery执行并等待scope.Complete()scope.Rollback()?它是否会创建一些"地方"并SqlCommand以某种方式了解它并将指令放在那里?

.net c# transactions transactionscope

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