ienumerator

Convert CollectionBase to List or data type usable with Linq

我的未来我决定 提交于 2019-12-04 08:19:07
问题 I am using Aspose cells to manipulate Excel spreadsheets. One of the types in the API is a collection of Pictures in the spreadsheet, which derives from CollectionBase: see this link: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/aspose.cells.pictures.html I want to convert this type to something that allows me to use Linq expressions What are the options for this? I guess I could iterate over it and manually add it to a new List<Picture> But is there a better way

List<T>.Enumerator IEnumerator.Reset() method implementation

时光毁灭记忆、已成空白 提交于 2019-12-04 07:37:53
Despite the fact, that IEnumerator.Reset method should never be used I found strange behavior of the method implementation within List<T> . No matter how you examine the .NET Framework Source Code (tried with reference source and ILSpy) the method is implemented as following: void System.Collections.IEnumerator.Reset() { if (version != list._version) { ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); } index = 0; current = default(T); } However, it looks like the method is never called at all! Consider the code: var list = new List<int>(1) { 3 }

Why does IEumerator<T> affect the state of IEnumerable<T> even the enumerator never reached the end?

纵然是瞬间 提交于 2019-12-03 06:06:41
I am curious why the following throws an error message (text reader closed exception) on the "last" assignment: IEnumerable<string> textRows = File.ReadLines(sourceTextFileName); IEnumerator<string> textEnumerator = textRows.GetEnumerator(); string first = textRows.First(); string last = textRows.Last(); However the following executes fine: IEnumerable<string> textRows = File.ReadLines(sourceTextFileName); string first = textRows.First(); string last = textRows.Last(); IEnumerator<string> textEnumerator = textRows.GetEnumerator(); What is the reason for the different behavior? You've

Is Yield Return == IEnumerable & IEnumerator?

你说的曾经没有我的故事 提交于 2019-12-03 04:13:51
问题 Is yield return a shortcut for implementing IEnumerable and IEnumerator ? 回答1: Yes, it is. You can find out a lot more about it in chapter 6 of my book, C# in Depth. Fortunately chapter 6 is available for free from Manning's web site. I also have two other articles on the book's web site. Feedback welcome. 回答2: To add to the link-fest, Raymond Chen did a nice little series on C# iterators a few months ago: http://blogs.msdn.com/oldnewthing/archive/2008/08/12/8849519.aspx http://blogs.msdn.com

Simple IEnumerator use (with example)

江枫思渺然 提交于 2019-12-03 01:34:08
问题 I am having trouble remembering how (but not why) to use IEnumerator s in C#. I am used to Java with its wonderful documentation that explains everything to beginners quite nicely. So please, bear with me. I have tried learning from other answers on these boards to no avail. Rather than ask a generic question that has already been asked before, I have a specific example that would clarify things for me. Suppose I have a method that needs to be passed an IEnumerable<String> object. All the

Is Yield Return == IEnumerable & IEnumerator?

痞子三分冷 提交于 2019-12-02 17:57:25
Is yield return a shortcut for implementing IEnumerable and IEnumerator ? Yes, it is. You can find out a lot more about it in chapter 6 of my book, C# in Depth. Fortunately chapter 6 is available for free from Manning's web site . I also have two other articles on the book's web site. Feedback welcome. To add to the link-fest, Raymond Chen did a nice little series on C# iterators a few months ago: http://blogs.msdn.com/oldnewthing/archive/2008/08/12/8849519.aspx http://blogs.msdn.com/oldnewthing/archive/2008/08/13/8854601.aspx http://blogs.msdn.com/oldnewthing/archive/2008/08/14/8862242.aspx

Simple IEnumerator use (with example)

被刻印的时光 ゝ 提交于 2019-12-02 15:20:57
I am having trouble remembering how (but not why) to use IEnumerator s in C#. I am used to Java with its wonderful documentation that explains everything to beginners quite nicely. So please, bear with me. I have tried learning from other answers on these boards to no avail. Rather than ask a generic question that has already been asked before, I have a specific example that would clarify things for me. Suppose I have a method that needs to be passed an IEnumerable<String> object. All the method needs to do is concatenate the letters roxxors to the end of every String in the iterator. It then

Cannot assign to item because it is a foreach iteration variable [duplicate]

做~自己de王妃 提交于 2019-12-02 15:03:37
问题 This question already has answers here : Why can't I modify the loop variable in a foreach? (6 answers) Why is foreach loop Read-Only in C# (3 answers) Why can't we assign a foreach iteration variable, whereas we can completely modify it with an accessor? (9 answers) Is there a reason for C#'s reuse of the variable in a foreach? (4 answers) Why is The Iteration Variable in a C# foreach statement read-only? (6 answers) Closed 3 months ago . Why can't we assign a value to the local variable in

How do I pick the most recently created folder using Foreach loop container in SSIS package?

拥有回忆 提交于 2019-12-02 06:43:58
问题 I've got an interesting challenge with SSIS. Using a for-each file enumerator, I need to pick the subfolder which has been most recently created, and then iterate through each of the files. Perhaps an example would explain better. The folders look something like this: c:\data\2011-0703 c:\data\2011-0626 c:\data\2011-0619 How could you get a for each file enumerator to pick the most recent folder? This could either be by looking at the creation date, or comparing the file names. I'm guessing

How do I pick the most recently created folder using Foreach loop container in SSIS package?

爱⌒轻易说出口 提交于 2019-12-02 03:51:02
I've got an interesting challenge with SSIS. Using a for-each file enumerator, I need to pick the subfolder which has been most recently created, and then iterate through each of the files. Perhaps an example would explain better. The folders look something like this: c:\data\2011-0703 c:\data\2011-0626 c:\data\2011-0619 How could you get a for each file enumerator to pick the most recent folder? This could either be by looking at the creation date, or comparing the file names. I'm guessing it would be done with an expression in the enumerator, just can't work out how! Couldn't find anything