小编cm0*_*007的帖子

如果属性为null,哪个/什么时候抛出异常?

我有以下课程:

class Foo
{
    public Foo()
        : this(new List<Bar>())
    {
    }

    public Foo(IEnumerable<Bar> bars)
    {
        Bars = bars;
    }

    public IEnumerable<Bar> Bars { get; set; }

    public Bar GetSingleBar(Data data)
    {
        // this method returns a single Bar from the Bars property above
        // this method returns the Bar which matches the data parameter
        // this method should not return null
        // this method throws a NoBarsFoundException if
        //   (a) Bars is empty or
        //   (b) no bar in Bars …
Run Code Online (Sandbox Code Playgroud)

c# exception-handling exception

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

F# 序列中的引导生成

我有以下代码:

open System
open System.Linq

type Child = {
    id: Guid
    name: int
    parent: Guid
}

type Parent = {
    id: Guid
    name: int
    children: seq<Guid>
}

let makeChild name parentId =
    {
        Child.id = Guid.NewGuid()
        name = name
        parent = parentId
    }

let makeParent (group: IGrouping<int, int>) =
    let id = Guid.NewGuid()
    let children = group |> Seq.map (fun x -> makeChild x id)
    let ids = children |> Seq.map (fun x -> x.id)
    ({
        Parent.id = id
        name …
Run Code Online (Sandbox Code Playgroud)

f#

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

Windows资源监视器中使用了哪种GUI控件?

我是Windows中GUI编程的新手.

Windows资源监视器(perfmon.exe /res)有四个具有渐变背景的条形图(CPU /磁盘/网络/内存),右侧的图表用于显示最近的CPU /磁盘/网络/内存使用情况.

我想知道在这个应用程序中使用了什么样的控件.它们是否可以在C++或C#中使用?

windows winapi perfmon

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

选择内部联接多对一关系,限制子表的结果数

我有以下表格:

create table TableA (
    Id int primary key identity,
    Name varchar(80) not null
)

create table TableB (
    Id int primary key identity,
    TableA_Id int not null foreign key references TableA(Id),
    Value varchar(80) not null
)
Run Code Online (Sandbox Code Playgroud)

我想写一个类似的查询

select TableA.Name, TableB.Value
    from TableA
    inner join TableB on TableA.Id = TableB.TableA_Id
    where TableA.Name like 'a%'
    order by TableB.Value asc
Run Code Online (Sandbox Code Playgroud)

除了我只想要每个TableA_Id中的前10名TableB.Value(按TableB.Value升序排序).

而不是每个TableB.Value都返回TableA.Name,我只想要每个的前10个值TableA.Name.

这样的查询会是什么?

sql one-to-many many-to-one sql-server-2008 sql-server-2008-r2

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

如何在 F# 中使用类型注释实现泛型

我有以下代码框架:

type MyException<'T> () =
    inherit Exception()

type IMyInterface =
    abstract member Method<'T when 'T : (new: unit -> 'T) and 'T :> Exception> : string -> int

type MyClass =
    interface IMyInterface with
        member this.Method s =
            let i = s.IndexOf "a"
            if i = -1 then raise (new MyException<'T> ())
            i
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下消息:

这种构造导致代码不像类型注释所指示的那样通用。类型变量“T”已被限制为“obj”类型。

编译时,obj传递给 MyException 而不是'T.

我需要对 进行上述类型约束IMyInterface.Method,并且还需要将传入的类型传递给MyExceptionin MyClass.Method。我怎样才能做到这一点?

generics f#

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