小编Abe*_*bel的帖子

将十六进制字符串转换为C#中的数值

我的表格上有一个文本框.我想将"0x31"作为字符串写入我的文本框,然后当我单击一个按钮时,我想将此字符串转换为0x31作为十六进制值.

如何将此字符串转换为十六进制值?

c# string hex

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

如何使用linq语句查询?

我有两个对象

List<Report> 
List<Newsletter>
Run Code Online (Sandbox Code Playgroud)

我需要某些属性,如

Id
Date
Status
text
Run Code Online (Sandbox Code Playgroud)

从两个名单.有没有办法合并这些列表并使用linq语句查询它以将特定属性作为单独的列表返回?请帮忙.

对象的结构如下:

Report
{
    int id,
    datetime reportDate, 
    enum Status,
    string text
};

Newsletter
{
    int id, 
    datetime newsletterDate,
    string Status,
    string text
};
Run Code Online (Sandbox Code Playgroud)

c# linq

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

一个方法如何只包含一个NotImplementedException并且仍然可以在不抛出的情况下运行?

如果我检查Reflector,FieldInfo.SetValueDirect它看起来如下:

C#,.NET 4.0:

[CLSCompliant(false)]
public virtual void SetValueDirect(TypedReference obj, object value)
{
    throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS"));
}
Run Code Online (Sandbox Code Playgroud)

而作为IL:

.method public hidebysig newslot virtual instance void SetValueDirect(valuetype System.TypedReference obj, object 'value') cil managed
{
    .custom instance void System.CLSCompliantAttribute::.ctor(bool) = { bool(false) }
    .maxstack 8
    L_0000: ldstr "NotSupported_AbstractNonCLS"
    L_0005: call string System.Environment::GetResourceString(string)
    L_000a: newobj instance void System.NotSupportedException::.ctor(string)
    L_000f: throw 
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我运行以下代码,它只是工作.

// test struct:
public struct TestFields
{
    public int MaxValue;
    public Guid SomeGuid;   // req for MakeTypeRef, which …
Run Code Online (Sandbox Code Playgroud)

c# reflection notimplementedexception

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

如何从 Xelement 获取根元素

我有以下 XElement:

 <Assembly name="3">
  <Component name="2" /> 
 </Assembly>
Run Code Online (Sandbox Code Playgroud)

我只想获取根元素。 <Assembly name="3">我看不到任何适合我的方法。

  XElement.????? I cant find XElement.Root;
Run Code Online (Sandbox Code Playgroud)

有什么线索吗?

c# xml linq xelement

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

为什么我要在Equals覆盖中执行object.ReferenceEquals(null,this)?

请考虑以下我正在审核的代码:

public override bool Equals(object other)
{
    return !object.ReferenceEquals(null, this)
           && (object.ReferenceEquals(this, other)
           || ((other is MyType) && this.InternalEquals((MyType)other)));
}
Run Code Online (Sandbox Code Playgroud)

这段代码的第一行引发了我的好奇心.每当this为null时,该方法应返回false.现在我很确定程序员打算用!object.ReferenceEquals(other, null)快捷方式编写null,但是他坚持认为this可以为null.我坚持认为它不能(除非有人使用直接内存操作).我们应该留下吗?

.net c# null this referenceequals

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

如何使用XSLT 3.0中的xsl:stream,xsl:accumulator,xs:fork?

我读了XSLT 3.0 W3C的文档在这里。我想知道如何使用这些元素:

(1) xsl:decimal-format
(2) xsl:stream
(3) xsl:accumulator
(4) xsl:accumulator-rule
(5) xsl:fork
Run Code Online (Sandbox Code Playgroud)

显然,这些是一些较少使用的元素。由于给出的示例有限,因此此处提供的答案将使XSLT的未来学习者受益。有人可以演示如何使用它们吗?

我知道很多要回答。因此,我将反对任何正确的部分答案,以期对其他人有用。

xml xslt xslt-3.0

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

获取或实现String.Zero和bool.Zero通常用于monoids

我试图将一些现有的代码重构为更单一的方法.现有代码包含IXInterface类似int和的接口和数字bool.该NUMERICS已经Zero在默认情况下,该接口有它作为一个属性gettor,但boolstring没有.一种方法是在界面中包含bool和string,但这很麻烦.

我想如果F#语言设法扩展数字的类型,也许我也可以为字符串和bool做我喜欢的特殊情况.

module MyZero =
    let inline get_zero () : ^a = ((^a) : (static member get_Zero : unit -> ^a)())

    type System.String with
        static member get_Zero() = System.String.Empty

type XR<'T when 'T : (static member get_Zero : unit -> 'T)> =
    | Expression of (SomeObj -> 'T)
    | Action of (int -> 'T)
    | Value of 'T
    | Empty

    member inline this.Execute(x: SomeObj) : 'T …
Run Code Online (Sandbox Code Playgroud)

generics monads f# monoids

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

如何在NUnit 3中使用ITestEventListener?

我想向NUnit添加一个自定义测试报告器。我已经用NUnit2完成了,但是现在我需要使用NUnit3。

要实现报告程序,我需要从框架中获取各种事件,例如测试的开始,结束和失败。

在NUnit2中,我曾经NUnitHook注册EventListener过它,效果很好。

在NUnit3中,我需要使用扩展点机制,但是当我将扩展点添加到项目中时,VisualStudio(2012旗舰版)立即无法发现NUnit测试。

[TypeExtensionPoint(Description = "Test Reporter Extension")]
    public class MyTestEventListener : ITestEventListener
    {

        public void OnTestEvent(string report)
        {
            Console.WriteLine(report);
        }

    }
Run Code Online (Sandbox Code Playgroud)

如果我从类中删除ITestEventListener实现声明,它将完美地重新发现测试。

[TypeExtensionPoint(Description = "Test Reporter Extension")]
    public class MyTestEventListener //: ITestEventListener
    {

        public void OnTestEvent(string report)
        {
            Console.WriteLine(report);
        }

    }
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?有没有更好的方法来实现呢?

c# nunit

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

Visual Basic 6.0传递值参考差异

在下面的代码中,我得到一个编译时错误,因为i它被视为一个变体.错误是:"ByRef Argument type mismatch.".

但是,如果我传递参数ByVal,没有错误原因?

Private Sub Command2_Click()
    Dim i, j As Integer
    i = 5
    j = 7
    Call Swap(i, j)
End Sub

Public Sub Swap(ByRef X As Integer, ByRef Y As Integer)
    Dim tmp As Integer
    tmp = X
    X = Y
    Y = tmp
End Sub
Run Code Online (Sandbox Code Playgroud)

vb6 pass-by-reference pass-by-value

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

两个日期之间的天数是多少?

我们想要找到两个日期之间的天数.当日期在同一年时,这很简单.

如果日期是在不同的年份,是否有内置的方法可以做到这一点,或者我们是否只需每年循环一次?

c# datetime

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