C# Enumerable yield and foreach

The professor today asks us in the class to solve this exercise in C# can someone help me out i'm lost... The purpose of this exercise and the next one is to emphasize the power of enumerables and the yield and foreach statements. Declare a generic static method Flatten that takes as argument an array of IEnumerable<T> and returns an IEnumerable<T> . Use foreach statements and

C#枚举yield和foreach

今天教授要求我们在课堂上解决这个练习,有人可以帮我解决我迷路... 这个练习和下一个练习的目的是强调枚举的力量,收益率和foreach语句。 声明一个泛型静态方法Flatten,它以IEnumerable<T>的数组作为参数并返回一个IEnumerable<T> 。 使用foreach语句和yield return语句。 该方法应该有这个标题: public static IEnumerable<T> Flatten<T>(IEnumerable<T>[] ebles) { ... } 如果您按以

How yield return works in c#

I have following piece of code. public static void main(string []args) { var intergers = GetCollection(); foreach(var val in intergers) { console.writeline(val); } } public IEnumerable<int> GetCollection() { yield return 10; var obj = new MyClass(); obj.performLargeAction(); yield return 1; var obj = new MyClass(); obj.perform(); yield return 2; consol

产量回报如何在c#中工作

我有以下一段代码。 public static void main(string []args) { var intergers = GetCollection(); foreach(var val in intergers) { console.writeline(val); } } public IEnumerable<int> GetCollection() { yield return 10; var obj = new MyClass(); obj.performLargeAction(); yield return 1; var obj = new MyClass(); obj.perform(); yield return 2; console.writeline("

IEnumerable and Recursion using yield return

I have an IEnumerable<T> method that I'm using to find controls in a WebForms page. The method is recursive and I'm having some problems returning the type I want when the yield return is returnig the value of the recursive call. My code looks as follows: public static IEnumerable<Control> GetDeepControlsByType<T>(this Control con

IEnumerable和递归使用yield return

我有一个IEnumerable<T>方法用于在WebForms页面中查找控件。 该方法是递归的,并且当yield return值是递归调用的值时,我有一些问题返回我想要的类型。 我的代码如下所示: public static IEnumerable<Control> GetDeepControlsByType<T>(this Control control) { foreach(Control c in control.Controls) { if (c is T)

What does LINQ return when the results are empty

I have a question about LINQ query. Normally a query returns a IEnumerable type. If the return is empty, not sure if it is null or not. I am not sure if the following ToList() will throw an exception or just a empty List<string> if nothing found in IEnumerable result? List<string> list = {"a"}; // is the result null or something else? IEnumerable<string> ilist = fro

当结果为空时,LINQ会返回什么结果?

我有一个关于LINQ查询的问题。 通常,查询返回一个IEnumerable类型。 如果返回为空,则不确定它是否为空。 我不确定如果在IEnumerable结果中找不到任何内容,下面的ToList()是否会抛出一个异常或只是一个空的List <string>? List<string> list = {"a"}; // is the result null or something else? IEnumerable<string> ilist = from x in list where x == "ABC" select x; // Or directly t

Deferred execution and eager evaluation

Could you please give me an example for Deferred execution with eager evaluation in C#? I read from MSDN that deferred execution in LINQ can be implemented either with lazy or eager evaluation. I could find examples in the internet for Deferred execution with lazy evaluation, however I could not find any example for Deferred execution with eager evaluation. Moreover, how deferred execution d

推迟执行和急切评估

您能否给我一个延期执行的例子,用C#进行急切的评估? 我从MSDN读到,LINQ中的延迟执行可以通过懒惰或急切的评估来实现。 我可以在因特网上找到延迟执行的例子,但我找不到任何延迟执行的例子。 此外,延期执行与懒惰评估有何不同? 在我看来,两者看起来都一样。 你能提供任何例子吗? 贝娄是我的回答,但也注意到Jon Skeet今天在他的博客上谈到了这个事实,即他对MSDN的“懒惰”含义并不完全确定,因为MSDN并没有真正

Change amount scrollbar moves on a panel

I have a panel with many child controls and with Autoscroll enabled. Clicking the arrow at the top or bottom of the scrollbar results in a tiny movement of a few pixels only: Can the amount of movement be controlled and set to a much larger value? Using the .NET Compact Framework. EDIT 1 In the full version of .NET, the VerticalScroll.SmallChange and VerticalScroll.LargeChange properties

更改数量滚动条在面板上移动

我有一个包含许多子控件的面板,并且启用了Autoscroll 。 单击滚动条顶部或底部的箭头只会导致几个像素的微小移动: 移动量可以控制并设置为更大的值吗? 使用.NET Compact Framework。 编辑1 在.NET的完整版本中,可以直接访问VerticalScroll.SmallChange和VerticalScroll.LargeChange属性。 但是这些在Compact Framework中不可用。 所以问题是如何在Compact Framework中做到这一点? 编辑2通过查看面板的AutoScrol

time size of Label (Compact Framework)

I refer to the Visual Studio design view. When adding a label using the full .NET framework, System.Windows.Forms.Label controls have an AutoSize property set to True by default. If I drop a Label control onto a form, the default font is "Microsoft Sans Serif, 12pt, Regular" and the height of the control is 20. Change the font to (say) "Tahoma, 14pt, Bold" and the height aut

标签(Compact Framework)的实时大小

我指的是Visual Studio设计视图。 使用完整的.NET框架添加标签时,默认情况下, System.Windows.Forms.Label控件的AutoSize属性设置为True。 如果我将一个Label控件拖放到表单上,则默认字体为“Microsoft Sans Serif,12pt,Regular”,控件的高度为20.将字体更改为(比如说)“Tahoma,14pt,Bold”和高度改为23.好。 但是在CF(Compact-Framework)中, Label控件没有AutoSize属性。 当我如上所述改变字体时, Label的高度不

Does C# 6.0 work for .NET 4.0?

I created a sample project, with C#6.0 goodies - null propagation and properties initialization as an example, set target version .NET 4.0 and it... works. public class Cat { public int TailLength { get; set; } = 4; public Cat Friend { get; set; } public string Mew() { return "Mew!"; } } class Program { static void Main(string[] args) { var cat = new Cat {Friend =

C#6.0是否适用于.NET 4.0?

我创建了一个示例项目,以C#6.0好东西 - 空传播和属性初始化为例,设置目标版本.NET 4.0及其...作品。 public class Cat { public int TailLength { get; set; } = 4; public Cat Friend { get; set; } public string Mew() { return "Mew!"; } } class Program { static void Main(string[] args) { var cat = new Cat {Friend = new Cat()}; Console.WriteLine(cat?.Friend.Mew());

WinForms temporary disable vertical scrollbar in panel

I have MSChart control within Panel in my form. Panel has AutoScroll property set to True. Once the chart gets too big - user is able to scroll through it. Once user presses Ctrl+MouseWheel I am enabling zoom in/out to the chart area. Currently on MouseWheel - both Panel and Chart are scrolling. How do I disable Panel scrollbars at the time when Chart is handling scrolling events? After d

WinForms临时禁用面板中的垂直滚动条

我在表格中的面板中有MSChart控件。 Panel将AutoScroll属性设置为True。 一旦图表变得太大 - 用户可以滚动浏览它。 一旦用户按下Ctrl + MouseWheel,我将启用放大/缩小到图表区域。 目前在MouseWheel上 - 面板和图表都在滚动。 Chart在处理滚动事件时如何禁用Panel滚动条? 禁用AutoScroll属性面板移动滚动到顶部并隐藏垂直滚动条 - 所以这不是我想要的: void Chart_KeyDown(object sender, KeyEventArgs e) { if (

How to reload registry settings ? (compact framework on a Symbol device)

I have a pocket pc from the Symbol manufactor. I would like to change programmaticaly the power timeouts and the backlight timeouts. The application in charge of this settings is written in C# and based on the Microsoft Compact Framework 3.5. I achieved to change these timeouts values : I changed registry keys in HKLM/System/CurrentControlSet/Control/Power for power timeouts and in HKCU/Contr

如何重新加载注册表设置? (Symbol设备上的紧凑框架)

我有一个来自Symbol制造商的袖珍电脑。 我想改变programmaticaly电源超时和背光超时。 负责此设置的应用程序使用C#编写,并基于Microsoft Compact Framework 3.5。 我实现了更改这些超时值:我更改了HKLM / System / CurrentControlSet / Control / Power中的电源超时注册表项以及HKCU / ControlPanel / Backlight中的背光超时注册表项。 它工作正常,但这些设置仅适用于设备的软复位后。 我希望在我的应用程序输入注册