小编Gur*_*raj的帖子

如何在C#中将字符串与枚举进行比较

string strName = "John";
public enum Name { John,Peter }

private void DoSomething(string myname)
{
case1:
     if(myname.Equals(Name.John) //returns false
     {

     }

case2:
     if(myname == Name.John) //compilation error
     {

     }

case3:
     if(myname.Equals(Name.John.ToString()) //returns true (correct comparision)
     {

     }
}
Run Code Online (Sandbox Code Playgroud)

当我使用.Equals它时是参考比较,当我使用==它时意味着值比较.

是否有更好的代码而不是将枚举值转换ToString()为比较?因为它破坏了值类型枚举的目的而且,ToString()在枚举上被弃用了?

.net c#

49
推荐指数
3
解决办法
6万
查看次数

泛型内存管理

关于如何管理强类型泛型的内存,我有疑问

List<int> ints1 = new List<int>();
ints1.Add(1); ints1.Add(2); ints1.Add(3);

int[] ints2 = new int[10]();
ints2.Add(6); ints2.Add(7); ints2.Add(8);
Run Code Online (Sandbox Code Playgroud)

问题1:我假设因为ints1初始化了一个新的关键字(new List<int>())它成为一个引用类型.值1,2,3在哪里存储在内存中(它们存储在堆栈中还是堆栈中)?

问题2:我知道之间的事情List<int>int[],List<int>可以扩展它的大小为任意大小在运行时,它被限制在int[]编译时.因此,如果值1,2,3存储在堆栈中,如果添加一个新项目List<int>说4,它将不会连续到前3个右侧,那么ints1将如何知道4的内存位置?

.net c# generics

8
推荐指数
3
解决办法
2143
查看次数

如何使用日志语句调试Gruntfile.js?

在我的Gruntfile中,如何在其处理中添加日志语句,如下例所示?

 karma: {
        unit: {
            configFile: "<%= grunt.option('Debug') ? 'build/karma.conf.js' : '' %>",
            console.log(configFile),
            singleRun: true,
            browsers: ['PhantomJS']
        },
    }
Run Code Online (Sandbox Code Playgroud)

jquery gruntjs karma-runner grunt-contrib-qunit

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

如何使用jasmine对保存的主干成功和错误响应进行单元测试

 onSaveEvent: function (event) {
                if (this.model !== null) {
                    var that = this;

                    this.model.save(this.model.toJSON(), {
                        success: function (model) {
                            that.model = model;
                            that.model.attributes.isDirty = false;
                        },

                        error: function (model, xhr) {
                            that.model.attributes.isDirty = true;
                        }
                    });
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

如何对模型进行单元测试,以保存Jasmine中的成功和错误响应?

jquery backbone.js jasmine jasmine-jquery jasmine-node

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

如何在VisualStudio.csproj中的<Target Name ="AfterBuild">中编写内联代码

如果$(ConfigurationName)不起作用 <AfterBuild>

<Target Name="AfterBuild">
if $(ConfigurationName) == Release (
    <Exec Command="grunt karma:unit --no-color &gt; grunt-karma-output.txt" IgnoreExitCode="true" />
    <Exec Command="type grunt-karma-output.txt" CustomErrorRegularExpression=".*mPhantomJS.*FAILED" IgnoreExitCode="false" />
)
</Target Name="AfterBuild">
Run Code Online (Sandbox Code Playgroud)

如果$(ConfigurationName)工作在 <PostBuildEvent>

<PostBuildEvent>
if $(ConfigurationName) == Release (
    <Exec Command="grunt karma:unit --no-color &gt; grunt-karma-output.txt" IgnoreExitCode="true" />
    <Exec Command="type grunt-karma-output.txt" CustomErrorRegularExpression=".*mPhantomJS.*FAILED" IgnoreExitCode="false" />
)
</PostBuildEvent>
Run Code Online (Sandbox Code Playgroud)

任何人都可以建议如何检查构建是否处于发布模式AfterBuild

msbuild build visual-studio gruntjs

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

如何在gruntfile.js中放置if else块

码:

karma: { 
   unit: { 
       if  ("<%= grunt.option('Release') %>" ) 
         {
          //do nothing 
         }
      else
        {
         configFile: 'build/karma.conf.js',
         singleRun: true,
         browsers: ['PhantomJS']
        }
   }
}
Run Code Online (Sandbox Code Playgroud)

如何在gruntfile.js中编写正确的if else语句.我正在使用visual studio项目文件调用gruntfile.js.

javascript jquery gruntjs grunt-contrib-qunit

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

在ASP中,<! - // - >意味着什么?

<script language="javascript">
    <!--    
             //some logic here 
    //-->
</script>
Run Code Online (Sandbox Code Playgroud)

什么<!-- //-->意思?.我认为他们是评论,然而,之前的双斜线 - >让我困惑.

html asp-classic

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