小编kr8*_*r85的帖子

C#方法可以返回一个方法吗?

C#中的方法可以返回一个方法吗?

例如,一个方法可以返回一个lambda表达式,但是我不知道我可以为这样的方法提供什么类型的参数,因为方法不是Type.这样的返回方法可以分配给某个委托.

以此概念为例:

public <unknown type> QuadraticFunctionMaker(float a , float b , float c)
{
    return (x) => { return a * x * x  + b * x + c; };
}

delegate float Function(float x);
Function QuadraticFunction = QuadraticFunctionMaker(1f,4f,3f);
Run Code Online (Sandbox Code Playgroud)

c# methods lambda return-type

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

等待系统删除文件

删除文件后刷新文件列表时出现问题.当我命令删除文件时,抛出了异常,因为刷新方法试图访问应该删除的文件.

经过一番思考和调试后,我得出结论,问题在于系统需要一些时间来删除文件.我这样解决它:

//Deleting file
System.Threading.Thread.Sleep(2000);
//Refreshing list
Run Code Online (Sandbox Code Playgroud)

它工作得很好.

我的问题是

是否有更优雅的方式等待系统删除文件,然后继续代码...?

c# filesystems multithreading delete-file

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

数字基元及其后缀

我想弄清楚这些后缀背后的真正含义是什么.换句话说,我正试图"翻译"它们.

+----+--------------+--------+
|    |     Type     | Suffix |
+----+--------------+--------+
|  1 | byte         | uy     |
|  2 | sbyte        | y      |
|  3 | int16        | s      |
|  4 | uint16       | us     |
|  5 | int, int32   |        |
|  6 | uint, uint32 | u      |
|  7 | int64        | L      |
|  8 | uint64       | UL     |
|  9 | float        |        |
| 10 | float        | f      |
| …
Run Code Online (Sandbox Code Playgroud)

f#

8
推荐指数
2
解决办法
644
查看次数

适用于Android的Visual Studio模拟器 - 运行模拟设备需要内部虚拟网络交换机

问题

我想使用Android的Visual Studio模拟器,但每当我尝试启动它时它都会失败.

在此输入图像描述

日志的最后部分是:

27.9.2015. 11:10:38: [Informational] ===== Session Started =====
27.9.2015. 11:10:38: [Informational] Microsoft Windows NT 6.3.9600.0 Windows 8.1 Pro with Media Center
27.9.2015. 11:10:38: [Informational] Virtualization type: UnknownOrNotVirtual
27.9.2015. 11:10:38: [Informational] Virtualization Version: alaska - 1072009
27.9.2015. 11:10:38: [Informational] Virtualization Serial Number: to be filled by o.e.m.
27.9.2015. 11:10:38: [Informational] Virtualization Product: z97-d3h-cf
27.9.2015. 11:10:38: [Informational] Display Adapter 0: Name: NVIDIA GeForce GTX 960, Version: 10.18.13.5362
27.9.2015. 11:10:38: [Informational] Display Adapter 1: Name: Intel(R) HD Graphics …
Run Code Online (Sandbox Code Playgroud)

android hyper-v visual-studio-2015

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

使用tilde获取int的MAX值

我尝试使用tilde获取int的MAX值.但是输出不是我所期望的.当我运行这个:

#include <stdio.h>
#include <limits.h>
int main(){
    int a=0;
    a=~a;
    printf("\nMax value: %d",-a);
    printf("\nMax value: %d",INT_MAX);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到输出:

最大值:1

最大值:2147483647

我想,(例如)如果我在RAM中有0000(我知道第一位显示的是数字pozitiv或negativ).在~ 0000 => 1111之后和 - (1111)=> 0111之后,我将获得MAX值.

c c++ memory

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

将ViewModel绑定到ContentControl作为其DataContext

我想在按钮点击时改变UserControls(我不会在这里复杂化,所以我只提到重要的部分).因此,想法是将这些UserControl的ViewModels绑定到ContentControl,然后使用DataTemplates将它们关联起来.这是代码:

<Window x:Class="Project.MainWindow">
<Window.Resources>
    <DataTemplate DataType="{x:Type UserControl:ViewUserControlViewModel}" >
        <UserControl:ViewUserControl/>
    </DataTemplate>
    <DataTemplate DataType="{x:Type UserControl:EditUserControlViewModel}" >
        <UserControl:EditUserControl/>
    </DataTemplate>
</Window.Resources>
<Grid>
    <ContentControl DataContext="{Binding UserControlViewModel}" />
    <Button Content="View" Click="ChangeToView()"/>
    <Button Content="Edit" Click="ChangeToEdit()"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

视图模型:

public class MainWindowViewModel : DependencyObject
{
    public DependencyObject UserControlViewModel
    {
        get { return (DependencyObject)GetValue(UserControlViewModelProperty); }
        set { SetValue(UserControlViewModelProperty, value); }
    }
    public static readonly DependencyProperty UserControlViewModelProperty = 
           DependencyProperty.Register("UserControlViewModel", typeof(DependencyObject), typeof(MainWindowViewModel), new PropertyMetadata());

    public MainWindowViewModel()
    {
        UserControlViewModel = new EditUserControlViewModel();
    }
}
Run Code Online (Sandbox Code Playgroud)

但这是一个问题.当我开始项目时,我只看到按钮而不是任何UserControls.我做错了什么?

c# wpf mvvm

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

简单的scala代码:从字符串数组返回第一个元素

我不知道如何修复此代码.它在returnFirstString中的某个地方"爆炸",但我不知道为什么.另外,我不知道如何使用println正确显示结果.这种方法可以吗?

所以这是代码:

def returnFirstString(a: Array[String]): Option[String]=
{
    if(a.isEmpty) { None }
    Some(a(0))
}
val emptyArrayOfStrings = Array.empty[String]
println(returnFirstString(emptyArrayOfStrings))
Run Code Online (Sandbox Code Playgroud)

scala

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

为什么初始迁移有依赖关系?

在没有任何事先迁移的情况下,我在核心应用程序中添加了自定义用户模型,以通过遵循文档条目Django 2.0 / 在 Django 中自定义身份验证来启用自定义身份验证

然后我进行了迁移:

$ python manage.py makemigrations

Migrations for 'core':
  core/migrations/0001_initial.py
    - Create model User
Run Code Online (Sandbox Code Playgroud)

0001_initial.py迁移类开始:

class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0009_alter_user_last_name_max_length'),
    ]
Run Code Online (Sandbox Code Playgroud)

我已经浏览了官方文档Django 2.0 / Migrations,这个文件显然是一个初始迁移,因为它有initial = True. 但是为什么它有一个以 开头的完整依赖链0009_alter_user_last_name_max_length?我做错了什么吗?

运行迁移时,输出如下:

$ python manage.py migrate  
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, core, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... …
Run Code Online (Sandbox Code Playgroud)

django database-migration

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

F#令人困惑的输出

我是F#初学者.我运行了这段代码:

let printMsg() =
    let msg = "Important"
    printfn "%s" msg
    let innerMsgChange() =
        let msg = "Very Important"
        printfn "%s" msg
    printfn "%s" msg
    innerMsgChange()
    printfn "%s" msg

printMsg()
Run Code Online (Sandbox Code Playgroud)

我期望文本输出将按以下顺序排列:

重要,非常重要,重要,重要

或这个

重要,非常重要,非常重要,重要

但我得到了这个

重要,重要,非常重要,重要

似乎这些函数不符合代码执行顺序.为什么,我错过了什么?

f#

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

为什么Scala没有枚举类型,当前设计有哪些好处?

他们决定不在Scala中实现枚举类型的原因是什么?当前语言设计的好处是什么(定义对象和扩展scala.Enumeration而不是创建新的枚举类型)?

scala language-design

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