小编alo*_*ica的帖子

给定(a*b)列表,返回(a*b列表)列表

也许是一个时髦的标题,但我遇到以下问题:

给定一个类型列表(a * b) list,我想创建一个带有类型的新列表(a * b list) list.一个例子:

给定列表let testList = [(1,"c");(2,"a");(1,"b")],我的函数应该返回[(1, ["c";"b"]; (2, ["a"])].

我有以下内容,但我有点坚持如何继续:

let rec toRel xs =
    match xs with
    | (a,b)::rest -> (a,[b])::toRel rest
    | _           -> []
Run Code Online (Sandbox Code Playgroud)

f# list

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

在 F# 交互窗口中显示完整字符串

如果我在 Visual Studio Code 中的 fsx 中输入以下内容

let longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Run Code Online (Sandbox Code Playgroud)

Alt …

f# f#-interactive visual-studio-code vscode-debugger

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

绑定滑块控件的事件

在视图(AudioView.xaml)中,我编写了以下代码

<Slider
    Name="AudioSlider"
    Width="200"
    Height="23"
    Grid.Column="0"
    IsSelectionRangeEnabled="True"
    IsSnapToTickEnabled="True"
    Maximum="{Binding Path=TotalAudioPlayingSeconds, Mode=OneTime}"
    Minimum="0"
    Style="{StaticResource CustomStyleForSlider}"
    Thumb.DragCompleted="{Binding AudioSliderChangedCommand}"
    TickFrequency="1"
    Value="{Binding Path=AudioPosition}"/>
Run Code Online (Sandbox Code Playgroud)

注意:还有文件AudioView.xaml.cs.

在视图模型class(AudioViewModel.cs)中,我定义了以下属性

public event DragCompletedEventHandler AudioSliderChangedCommand;
Run Code Online (Sandbox Code Playgroud)

并在视图模型类(AudioViewModel.cs)的构造函数中

this.AudioSliderChangedCommand = new DragCompletedEventHandler(OnAudioSliderChanged);
Run Code Online (Sandbox Code Playgroud)

在编译期间,我收到以下错误

错误8 DragCompleted ="{Binding AudioSliderChangedCommand}"无效.{Binding AudioSliderChangedCommand}不是有效的事件处理程序方法名称.只有生成的或代码隐藏类上的实例方法才有效.

wpf xaml binding mvvm

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

如何证明Windows Phone应用程序中TextBlock的文本是正确的?

我想将一个合理的文本放入文本块但是给我一个错误.为什么?我能解决吗?

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <TextBlock Height="220" 
               HorizontalAlignment="Left" 
               Margin="102,174,0,0" 
               Name="textBlock1" 
               Text="TextBlock sdfg asfgbfgb  adf ab afg g " 
               TextAlignment="Justify"
               VerticalAlignment="Top" 
               Width="255" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

windows textblock windows-phone-7

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

c#字典查找抛出"索引超出了数组的范围"

我收到了一个错误报告,似乎来自以下代码:

public class AnimationChannelCollection : ReadOnlyCollection<BoneKeyFrameCollection>
{
        private Dictionary<string, BoneKeyFrameCollection> dict =
            new Dictionary<string, BoneKeyFrameCollection>();

        private ReadOnlyCollection<string> affectedBones;

       // This immutable data structure should not be created by the library user
        internal AnimationChannelCollection(IList<BoneKeyFrameCollection> channels)
            : base(channels)
        {
            // Find the affected bones
            List<string> affected = new List<string>();
            foreach (BoneKeyFrameCollection frames in channels)
            {
                dict.Add(frames.BoneName, frames);
                affected.Add(frames.BoneName);
            }
            affectedBones = new ReadOnlyCollection<string>(affected);

        }

        public BoneKeyFrameCollection this[string boneName]
        {           
            get { return dict[boneName]; }
        }
}
Run Code Online (Sandbox Code Playgroud)

这是读取字典的调用代码:

public override Matrix GetCurrentBoneTransform(BonePose pose) …
Run Code Online (Sandbox Code Playgroud)

c# dictionary

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

热来宣布一个空的地图/字典?

我想用Map初始化一个递归函数.要声明具有值的只读字典,我们可以这样做:

let dictionary1  = dict [ (1, "a"); (2, "b"); (3, "c") ]       
Run Code Online (Sandbox Code Playgroud)

在线尝试!

现在,我想创建一个空字典.怎么实现呢?

我正在寻找像:

let dictionary1 = {} // <- ok this is js
let (stuff, dictionary2) = parseRec("whatever", dictionary1)
Run Code Online (Sandbox Code Playgroud)

f#

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

我怎样才能用容器模板?

我不认为我的标题是准确的,所以只需转到代码.

namespace Fobaizer
{
  template <typename T, typename C>
  static T GetItemFromContainer(const C &container) {
    T item = container[0]; // do something. 0 or iterator
    return item;
  }
}
Run Code Online (Sandbox Code Playgroud)

例:

MyClass myClass = Fobaizer::GetItemFromContainer<MyClass, vector<MyClass>(myVector);
Run Code Online (Sandbox Code Playgroud)

要么

MyClass myClass = Fobaizer::GetItemFromContainer<MyClass, deque<MyClass>(myDeque);
Run Code Online (Sandbox Code Playgroud)

这里C是任何容器,如std::dequestd::vector.我搜索没有任何lib的C98解决方案(boost,QT等)

事实上,我正在寻找像IEnumerableC#这样的东西.

任何的想法 ?

谢谢.

c++ containers templates

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

Debug.log()和print()函数有什么区别?

Debug.Log("Hello there!");
print("Hello there");
Run Code Online (Sandbox Code Playgroud)

这两个语句在控制台上显示相同的输出,那有什么区别?

c#

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

如何将类型“System.Collections.Generic.Dictionary&gt;”隐式转换为“System.Collections.Generic.IDictionary&gt;”?

当我将 a 分配Dictionary<int, HashSet<int>>给 a 时IDictionary<int, IEnumerable<int>>,出现以下错误:

编译错误(第 27 行,第 9 列):无法将类型“System.Collections.Generic.Dictionary>”隐式转换为“System.Collections.Generic.IDictionary>”。存在显式转换(您是否缺少演员表?)

错误很明显。缺少演员表。为什么我需要演员阵容?Dictionary<T,U>执行IDictionary<T,U>HashSet<T>执行IEnumerable<T>

using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{   
    public class A
    {
        public IDictionary<int, IEnumerable<int>> D { get; set; }
        public IEnumerable<int> H { get; set; }
    }

    public static void Main()
    {
        var hashSet = new HashSet<int>{1,2,1};
        var a = new A { H = hashSet };
        PrintCollection(a.H);

        var d = new …
Run Code Online (Sandbox Code Playgroud)

c# oop

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