我有一系列数字:
var seq = new List<int> { 1, 3, 12, 19, 33 };
Run Code Online (Sandbox Code Playgroud)
并且我想将其转换为新序列,其中将数字添加到前面的数字以创建新序列:
{ 1, 3, 12, 19, 33 } --> {1, 4, 16, 35, 68 }
Run Code Online (Sandbox Code Playgroud)
我想出了以下内容,但我不喜欢状态变量'count'.我也不喜欢这样一个事实,即我使用值Enumerable而不采取行动.
int count = 1;
var summed = values.Select(_ => values.Take(count++).Sum());
Run Code Online (Sandbox Code Playgroud)
怎么可能呢?
我一直在阅读DI,它似乎是一个简单的概念.我没有得到的是容器.让我们说一下,我想创建自己的容器.像"detect"这样的动词被使用,我不知道容器如何"检测"创建了一个新的依赖对象并且知道注入它的依赖关系.对我而言,容器似乎是一个美化的工厂.
任何人都可以解释一个容器是如何实际实现的,或者可能指向一个资源?
谢谢!
假设目前的季度是3,年份是2011年.我怎样才能获得最后5个季度
期望的输出:
Q3-2011
Q2-2011
Q1-2011
Q4-2010
Q3-2010
Run Code Online (Sandbox Code Playgroud)
Q和' - '被追加.
我正在努力
int generateQuater = 5;
int currentQuater = 3;//GetQuarter(DateTime.Now.Month);
int currentYear = DateTime.Now.Year;
List<string> lstQuaterYear = new List<string>();
lstQuaterYear.Add(string.Concat('Q',currentQuater, '-', currentYear));
for (int i = generateQuater; i > 0; i++)
{
//code to be placed
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我目前正在开发一个桌面C#WPF应用程序,其目标是使其外观和感觉就像一个"real"Windows应用商店应用程序.
我想添加一个appbar应该在用户从底部向上滑动时显示的内容.要在普通应用程序中执行此操作,只需将手指放在屏幕区域外,然后向上滑动即可.但是,如果我在全屏WPF程序中执行此操作,则不会收到任何TouchDown或TouchMove事件 - 可能是因为在进入实际屏幕区域时手指已经关闭.我也尝试过Manipulation框架,但这里结果相同.即使我使用WndProc或其他钩子直接挂钩到消息队列,我根本没有事件.
有趣的是,我可以看到"touch cursor"屏幕上的移动,所以至少通知底层框架中的某些内容.
有谁知道如何做到这一点?
ps由于硬件连接问题,我不能仅仅使用Windows应用商店应用程序;-)
我有以下ViewModel-Property:
public List<List<string>> Names .... //It's a dependency property
Run Code Online (Sandbox Code Playgroud)
在我看来,我希望ItemsControl有一个ItemsControl:
<ItemsControl ItemsSource="{Binding Names}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ?????}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Text="{Binding ??????}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
我如何绑定到的项目List?在上面的代码示例中,我标记了它?????
我已经阅读了许多有关在开发中使用IoC容器的有趣文章.在许多情况下,作者建议我们编写自己的简单包装器,它隐藏了读取容器的接口,如Ninject,Castle.Windsor,Unity等.
包装器的实现看起来像这样(对于Ninject):
/// <summary>
/// Contains links for service contract and realization.
/// </summary>
public static class IoC
{
static readonly IKernel kernel;
static IoC()
{
kernel = new StandardKernel();
}
public static void RegisterService<T>(Type service)
{
kernel.Bind<T>().To(service);
}
public static T Resolve<T>()
{
return kernel.Get<T>();
}
}
Run Code Online (Sandbox Code Playgroud)
好的,但是如何使用此模式的高级功能?例如,我喜欢使用像InRequestScope()或InSingletonScope()这样的生命周期管理修饰符,许多容器都支持这种修饰符.使用上面的模式,我可以丢弃ninject并使用15行实现.区别在哪里?
我还看了一下CommonServiceLocator试图找到丰富的包装器,但它与我的IoC类没有太大区别.现在我认为我不应该制作自己的自行车并直接使用全功能容器.你呢?
我有一个外部系统,它给我一个对象值(我知道这个值总是一个盒装整数类型).我想以通常的方式增加它:int value += otherIntValue,但我从编译器得到一个错误:
运算符'+ ='不能应用于类型的操作数
例如:
//source values i cannot to change it
object targetInt = 100;
int incrementedValue = 20;
//usual way - not works
targetInt += incrementedValue;
//ugly workaround
targetInt = ((int) targetInt) + incrementedValue;
Run Code Online (Sandbox Code Playgroud)
有没有办法增加int和object的实例targetInt += incrementedValue;?