小编Fun*_*nut的帖子

每个Dictionary条目必须具有关联的键属性

我正在使用C#和来自GalaSoft的MVVM-Light Toolkit编写Windows 8.1 App.

我只有以下代码:

<Application.Resources>
    <vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>      
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

出现错误"每个词典条目必须具有关联的键属性",并且只有在我删除时才会消失

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary> 
Run Code Online (Sandbox Code Playgroud)

要么

    <vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这里的问题是什么?

c# xaml dictionary mvvm

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

SQLite的; "无法添加PRIMARY KEY列"-Exception

今天我开始处理数据库.我已经安装了SQLite和SQLite-net.我正在使用C#编写Windows 8.1应用程序.

我只有以下几点:

一个模型:

public class Subject
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public string Name { get; set; }    
}
Run Code Online (Sandbox Code Playgroud)

App.Xaml.cs中的OnLaunched-Event包含:

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
[...]
    // Get a reference to the SQLite database
    DBPath = Path.Combine(
        Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Subjects.s3db");
    // Initialize the database if necessary
    using (var db = new SQLite.SQLiteConnection(DBPath))
    {
        // Create the tables if they don't exist
        db.CreateTable<Subject>();
    }
[...]
}
Run Code Online (Sandbox Code Playgroud)

当我启动它时,我在db.CreateTable()之后得到以下错误; 执行:

无法添加PRIMARY KEY列.

这里出了什么问题?我真的很感激你的帮助.

非常感谢你.

问候,FunkyPeanut

c# sql

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

当返回类型为Task &lt;string&gt;时,为什么该方法返回一个字符串?

我对C#中的异步编程有疑问。我想知道为什么具有Task的返回类型的函数必须返回字符串。因此,即使我返回了一个字符串,它也会再次包裹在Task中-为什么?

问题是我必须向学生解释这些东西。即使我刚刚等待函数返回的结果,将重行字符串包装在Task对象中的背后是什么原因呢?我以为await语句会阻止方法的继续直到结果到达-这意味着在函数调用(await GetWeatherAsync())上没有什么可以等待的,因为结果已经在那里...

这是我的示例代码:

    static async void Download()
    {
        //I have just awaited the result in the function call. Why do I have to do this again at this point?
        Console.WriteLine(await GetWeatherAsync());
    }

    private static async Task<string> GetWeatherAsync()
    {
        HttpClient client = new HttpClient();
        Task<HttpResponseMessage> t = client.GetAsync("http://localhost:59534/WeatherService.svc/rest?weekDay=Monday");
        HttpResponseMessage serverResponse = await t;

        return await serverResponse.Content.ReadAsStringAsync();
    }
Run Code Online (Sandbox Code Playgroud)

如果没有最后的等待,一切对我来说至少是有意义的-因为我要返回一个可能仍有工作要做的真实任务...

.net c# asynchronous async-await

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

为什么"在CPU绑定上使用异步[...]方法[提供]没有任何好处,并导致更多的开销."

我来到这篇文章.在"选择同步或异步操作方法"下,作者声明在下列情况下不应使用异步操作方法:

这些操作主要是CPU操作,而不是涉及大量磁盘或网络开销的操作.在CPU绑定操作上使用异步操作方法不会带来任何好处并导致更多开销.

我不明白为什么会这样.因为如果我有一个计算斐波纳契数的方法,这个方法占用了30秒的计算,那么这个调用主要是CPU绑定的.不使此异步会阻塞调用线程30秒并使应用程序无响应.

你能用这个推理帮助我吗?

c# asp.net-mvc multithreading asynchronous async-await

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

将数据结构副本分配给新实例的时间复杂度是多少?

我只有一个小问题:我有一个AVL树,并希望将它1:1复制到一个新实例.我所做的是创建一个AVLTreeClass的新实例,并为其分配我想用等号复制的树(在C++ 11中).

我不得不担心时间的复杂性吗?或者这是否在O(1)中运行?

非常感谢您的帮助!

FunkyPeanut

big-o avl-tree time-complexity data-structures c++11

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