why does the compiler NOT complain about not all paths returning?
I have this inside of a do..while
:
yield return string.Join(",", arr) + "n";
Why isn't the compiler complaining that not all of the code paths are returning a value?
The full code example is below:
public static IEnumerable<string> Convert(Stream stream)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(stream);
var csvContent = string.Empty;
do
{
while (reader.Read())
{
var arr = new List<string>();
for (int i = 0; i < reader.FieldCount; i++)
{
var cell = reader[i]?.ToString();
var format = reader.GetNumberFormatString(i);
if (format == "mm\/dd\/yyyy" || format == "M/d/yyyy")
{
cell = cell.Replace(" 12:00:00 AM", "");
}
if (format == "h\:mm\:ss AM/PM")
{
cell = cell.Replace("12/31/1899 ", "");
}
var processedCell = cell == null ? string.Empty : cell.Contains(",") ? """ + cell + """ : cell;
arr.Add(processedCell);
}
yield return string.Join(",", arr) + "n";
}
} while (reader.NextResult());
}
There is no return
keyword as the last line!
c# .net visual-studio visual-studio-2017
|
show 2 more comments
I have this inside of a do..while
:
yield return string.Join(",", arr) + "n";
Why isn't the compiler complaining that not all of the code paths are returning a value?
The full code example is below:
public static IEnumerable<string> Convert(Stream stream)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(stream);
var csvContent = string.Empty;
do
{
while (reader.Read())
{
var arr = new List<string>();
for (int i = 0; i < reader.FieldCount; i++)
{
var cell = reader[i]?.ToString();
var format = reader.GetNumberFormatString(i);
if (format == "mm\/dd\/yyyy" || format == "M/d/yyyy")
{
cell = cell.Replace(" 12:00:00 AM", "");
}
if (format == "h\:mm\:ss AM/PM")
{
cell = cell.Replace("12/31/1899 ", "");
}
var processedCell = cell == null ? string.Empty : cell.Contains(",") ? """ + cell + """ : cell;
arr.Add(processedCell);
}
yield return string.Join(",", arr) + "n";
}
} while (reader.NextResult());
}
There is no return
keyword as the last line!
c# .net visual-studio visual-studio-2017
@DavidG exactly! and my signature is promising anIEnumerable<string>
return value, not avoid
!
– l--''''''---------''''''''''''
Nov 23 at 1:27
1
That is the nature of yield return. Check example from Microsoft. docs.microsoft.com/en-us/dotnet/csharp/language-reference/… If exponent is 0, it is the same as yours.
– wannadream
Nov 23 at 1:29
3
Iterators march to a different drummer. Not returning anything is just fine, it returns an empty iterator.
– Hans Passant
Nov 23 at 1:31
@HansPassant very nice explanation, but where does it say that?
– l--''''''---------''''''''''''
Nov 23 at 1:32
2
The C# language specification, chapter 10.4.4.1. It doesn't exactly yell it out.
– Hans Passant
Nov 23 at 1:36
|
show 2 more comments
I have this inside of a do..while
:
yield return string.Join(",", arr) + "n";
Why isn't the compiler complaining that not all of the code paths are returning a value?
The full code example is below:
public static IEnumerable<string> Convert(Stream stream)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(stream);
var csvContent = string.Empty;
do
{
while (reader.Read())
{
var arr = new List<string>();
for (int i = 0; i < reader.FieldCount; i++)
{
var cell = reader[i]?.ToString();
var format = reader.GetNumberFormatString(i);
if (format == "mm\/dd\/yyyy" || format == "M/d/yyyy")
{
cell = cell.Replace(" 12:00:00 AM", "");
}
if (format == "h\:mm\:ss AM/PM")
{
cell = cell.Replace("12/31/1899 ", "");
}
var processedCell = cell == null ? string.Empty : cell.Contains(",") ? """ + cell + """ : cell;
arr.Add(processedCell);
}
yield return string.Join(",", arr) + "n";
}
} while (reader.NextResult());
}
There is no return
keyword as the last line!
c# .net visual-studio visual-studio-2017
I have this inside of a do..while
:
yield return string.Join(",", arr) + "n";
Why isn't the compiler complaining that not all of the code paths are returning a value?
The full code example is below:
public static IEnumerable<string> Convert(Stream stream)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(stream);
var csvContent = string.Empty;
do
{
while (reader.Read())
{
var arr = new List<string>();
for (int i = 0; i < reader.FieldCount; i++)
{
var cell = reader[i]?.ToString();
var format = reader.GetNumberFormatString(i);
if (format == "mm\/dd\/yyyy" || format == "M/d/yyyy")
{
cell = cell.Replace(" 12:00:00 AM", "");
}
if (format == "h\:mm\:ss AM/PM")
{
cell = cell.Replace("12/31/1899 ", "");
}
var processedCell = cell == null ? string.Empty : cell.Contains(",") ? """ + cell + """ : cell;
arr.Add(processedCell);
}
yield return string.Join(",", arr) + "n";
}
} while (reader.NextResult());
}
There is no return
keyword as the last line!
c# .net visual-studio visual-studio-2017
c# .net visual-studio visual-studio-2017
edited Nov 23 at 1:28
asked Nov 23 at 1:23
l--''''''---------''''''''''''
9,868232532876
9,868232532876
@DavidG exactly! and my signature is promising anIEnumerable<string>
return value, not avoid
!
– l--''''''---------''''''''''''
Nov 23 at 1:27
1
That is the nature of yield return. Check example from Microsoft. docs.microsoft.com/en-us/dotnet/csharp/language-reference/… If exponent is 0, it is the same as yours.
– wannadream
Nov 23 at 1:29
3
Iterators march to a different drummer. Not returning anything is just fine, it returns an empty iterator.
– Hans Passant
Nov 23 at 1:31
@HansPassant very nice explanation, but where does it say that?
– l--''''''---------''''''''''''
Nov 23 at 1:32
2
The C# language specification, chapter 10.4.4.1. It doesn't exactly yell it out.
– Hans Passant
Nov 23 at 1:36
|
show 2 more comments
@DavidG exactly! and my signature is promising anIEnumerable<string>
return value, not avoid
!
– l--''''''---------''''''''''''
Nov 23 at 1:27
1
That is the nature of yield return. Check example from Microsoft. docs.microsoft.com/en-us/dotnet/csharp/language-reference/… If exponent is 0, it is the same as yours.
– wannadream
Nov 23 at 1:29
3
Iterators march to a different drummer. Not returning anything is just fine, it returns an empty iterator.
– Hans Passant
Nov 23 at 1:31
@HansPassant very nice explanation, but where does it say that?
– l--''''''---------''''''''''''
Nov 23 at 1:32
2
The C# language specification, chapter 10.4.4.1. It doesn't exactly yell it out.
– Hans Passant
Nov 23 at 1:36
@DavidG exactly! and my signature is promising an
IEnumerable<string>
return value, not a void
!– l--''''''---------''''''''''''
Nov 23 at 1:27
@DavidG exactly! and my signature is promising an
IEnumerable<string>
return value, not a void
!– l--''''''---------''''''''''''
Nov 23 at 1:27
1
1
That is the nature of yield return. Check example from Microsoft. docs.microsoft.com/en-us/dotnet/csharp/language-reference/… If exponent is 0, it is the same as yours.
– wannadream
Nov 23 at 1:29
That is the nature of yield return. Check example from Microsoft. docs.microsoft.com/en-us/dotnet/csharp/language-reference/… If exponent is 0, it is the same as yours.
– wannadream
Nov 23 at 1:29
3
3
Iterators march to a different drummer. Not returning anything is just fine, it returns an empty iterator.
– Hans Passant
Nov 23 at 1:31
Iterators march to a different drummer. Not returning anything is just fine, it returns an empty iterator.
– Hans Passant
Nov 23 at 1:31
@HansPassant very nice explanation, but where does it say that?
– l--''''''---------''''''''''''
Nov 23 at 1:32
@HansPassant very nice explanation, but where does it say that?
– l--''''''---------''''''''''''
Nov 23 at 1:32
2
2
The C# language specification, chapter 10.4.4.1. It doesn't exactly yell it out.
– Hans Passant
Nov 23 at 1:36
The C# language specification, chapter 10.4.4.1. It doesn't exactly yell it out.
– Hans Passant
Nov 23 at 1:36
|
show 2 more comments
2 Answers
2
active
oldest
votes
Because you are using yield return. yield return method ends not with return, but actually with yield break and last yield break can be omitted
UPD. This is example of old code (Robotics Studio and Unity) where yield break on last line is exists
1
"last yield break can be omitted" - What? No. That's not right.
– Enigmativity
Nov 23 at 1:41
I've updated answer with code sample from book ~2008 year.
– Alexei Shcherbakov
Nov 23 at 1:56
2
Thanks for posting an answer. Please beware that pictures of code are frowned upon on SO because one can't copy/paste to try it. Could you please update your answer?
– Jacques Gaudin
Nov 23 at 8:30
How do you qualify “frowned upon” when this is the accepted answer?
– l--''''''---------''''''''''''
Nov 23 at 11:04
first code sample is from copyrighted book and second was founded by google image search. I remember that 'yield break' was necessary for Visual Studio more than 10 years ago (I even can't remember - Visual Studio 2005 Beta 2 or RTM), so this is only "historical" sample - in modern version of C# language it is not necessary. So I tried to find examples of 'yield break' in Internet in pre2005-2008 years :-)
– Alexei Shcherbakov
Nov 23 at 20:18
add a comment |
This is an exception in connection with the IEnumerable
iterator pattern and the yield return
keyword. In this case, the compiler constructs its state machine for the iterator runtime, and does not apply the same set of path coverage as it does with linear methods.
The semantics goes, "an iterator that does not produce, is empty, and this is at the same time a valid substitution for any code path that does not explicitely return a value".
The key to understanding this is that the compiler reforms methods that constitute iterators, to code that does no longer have uninitialized return values. See C# standard chapter 10.4.4.1 for an example.
Related: https://stackoverflow.com/a/9631242/1132334
another words, you are in agreement with hans?
– l--''''''---------''''''''''''
Nov 23 at 1:36
we both are in agreement with the specification. only that Hans obviously knows it by heart, and I have to look it up.
– dlatikay
Nov 23 at 1:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439655%2fwhy-does-the-compiler-not-complain-about-not-all-paths-returning%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Because you are using yield return. yield return method ends not with return, but actually with yield break and last yield break can be omitted
UPD. This is example of old code (Robotics Studio and Unity) where yield break on last line is exists
1
"last yield break can be omitted" - What? No. That's not right.
– Enigmativity
Nov 23 at 1:41
I've updated answer with code sample from book ~2008 year.
– Alexei Shcherbakov
Nov 23 at 1:56
2
Thanks for posting an answer. Please beware that pictures of code are frowned upon on SO because one can't copy/paste to try it. Could you please update your answer?
– Jacques Gaudin
Nov 23 at 8:30
How do you qualify “frowned upon” when this is the accepted answer?
– l--''''''---------''''''''''''
Nov 23 at 11:04
first code sample is from copyrighted book and second was founded by google image search. I remember that 'yield break' was necessary for Visual Studio more than 10 years ago (I even can't remember - Visual Studio 2005 Beta 2 or RTM), so this is only "historical" sample - in modern version of C# language it is not necessary. So I tried to find examples of 'yield break' in Internet in pre2005-2008 years :-)
– Alexei Shcherbakov
Nov 23 at 20:18
add a comment |
Because you are using yield return. yield return method ends not with return, but actually with yield break and last yield break can be omitted
UPD. This is example of old code (Robotics Studio and Unity) where yield break on last line is exists
1
"last yield break can be omitted" - What? No. That's not right.
– Enigmativity
Nov 23 at 1:41
I've updated answer with code sample from book ~2008 year.
– Alexei Shcherbakov
Nov 23 at 1:56
2
Thanks for posting an answer. Please beware that pictures of code are frowned upon on SO because one can't copy/paste to try it. Could you please update your answer?
– Jacques Gaudin
Nov 23 at 8:30
How do you qualify “frowned upon” when this is the accepted answer?
– l--''''''---------''''''''''''
Nov 23 at 11:04
first code sample is from copyrighted book and second was founded by google image search. I remember that 'yield break' was necessary for Visual Studio more than 10 years ago (I even can't remember - Visual Studio 2005 Beta 2 or RTM), so this is only "historical" sample - in modern version of C# language it is not necessary. So I tried to find examples of 'yield break' in Internet in pre2005-2008 years :-)
– Alexei Shcherbakov
Nov 23 at 20:18
add a comment |
Because you are using yield return. yield return method ends not with return, but actually with yield break and last yield break can be omitted
UPD. This is example of old code (Robotics Studio and Unity) where yield break on last line is exists
Because you are using yield return. yield return method ends not with return, but actually with yield break and last yield break can be omitted
UPD. This is example of old code (Robotics Studio and Unity) where yield break on last line is exists
edited Nov 23 at 1:59
answered Nov 23 at 1:40
Alexei Shcherbakov
28225
28225
1
"last yield break can be omitted" - What? No. That's not right.
– Enigmativity
Nov 23 at 1:41
I've updated answer with code sample from book ~2008 year.
– Alexei Shcherbakov
Nov 23 at 1:56
2
Thanks for posting an answer. Please beware that pictures of code are frowned upon on SO because one can't copy/paste to try it. Could you please update your answer?
– Jacques Gaudin
Nov 23 at 8:30
How do you qualify “frowned upon” when this is the accepted answer?
– l--''''''---------''''''''''''
Nov 23 at 11:04
first code sample is from copyrighted book and second was founded by google image search. I remember that 'yield break' was necessary for Visual Studio more than 10 years ago (I even can't remember - Visual Studio 2005 Beta 2 or RTM), so this is only "historical" sample - in modern version of C# language it is not necessary. So I tried to find examples of 'yield break' in Internet in pre2005-2008 years :-)
– Alexei Shcherbakov
Nov 23 at 20:18
add a comment |
1
"last yield break can be omitted" - What? No. That's not right.
– Enigmativity
Nov 23 at 1:41
I've updated answer with code sample from book ~2008 year.
– Alexei Shcherbakov
Nov 23 at 1:56
2
Thanks for posting an answer. Please beware that pictures of code are frowned upon on SO because one can't copy/paste to try it. Could you please update your answer?
– Jacques Gaudin
Nov 23 at 8:30
How do you qualify “frowned upon” when this is the accepted answer?
– l--''''''---------''''''''''''
Nov 23 at 11:04
first code sample is from copyrighted book and second was founded by google image search. I remember that 'yield break' was necessary for Visual Studio more than 10 years ago (I even can't remember - Visual Studio 2005 Beta 2 or RTM), so this is only "historical" sample - in modern version of C# language it is not necessary. So I tried to find examples of 'yield break' in Internet in pre2005-2008 years :-)
– Alexei Shcherbakov
Nov 23 at 20:18
1
1
"last yield break can be omitted" - What? No. That's not right.
– Enigmativity
Nov 23 at 1:41
"last yield break can be omitted" - What? No. That's not right.
– Enigmativity
Nov 23 at 1:41
I've updated answer with code sample from book ~2008 year.
– Alexei Shcherbakov
Nov 23 at 1:56
I've updated answer with code sample from book ~2008 year.
– Alexei Shcherbakov
Nov 23 at 1:56
2
2
Thanks for posting an answer. Please beware that pictures of code are frowned upon on SO because one can't copy/paste to try it. Could you please update your answer?
– Jacques Gaudin
Nov 23 at 8:30
Thanks for posting an answer. Please beware that pictures of code are frowned upon on SO because one can't copy/paste to try it. Could you please update your answer?
– Jacques Gaudin
Nov 23 at 8:30
How do you qualify “frowned upon” when this is the accepted answer?
– l--''''''---------''''''''''''
Nov 23 at 11:04
How do you qualify “frowned upon” when this is the accepted answer?
– l--''''''---------''''''''''''
Nov 23 at 11:04
first code sample is from copyrighted book and second was founded by google image search. I remember that 'yield break' was necessary for Visual Studio more than 10 years ago (I even can't remember - Visual Studio 2005 Beta 2 or RTM), so this is only "historical" sample - in modern version of C# language it is not necessary. So I tried to find examples of 'yield break' in Internet in pre2005-2008 years :-)
– Alexei Shcherbakov
Nov 23 at 20:18
first code sample is from copyrighted book and second was founded by google image search. I remember that 'yield break' was necessary for Visual Studio more than 10 years ago (I even can't remember - Visual Studio 2005 Beta 2 or RTM), so this is only "historical" sample - in modern version of C# language it is not necessary. So I tried to find examples of 'yield break' in Internet in pre2005-2008 years :-)
– Alexei Shcherbakov
Nov 23 at 20:18
add a comment |
This is an exception in connection with the IEnumerable
iterator pattern and the yield return
keyword. In this case, the compiler constructs its state machine for the iterator runtime, and does not apply the same set of path coverage as it does with linear methods.
The semantics goes, "an iterator that does not produce, is empty, and this is at the same time a valid substitution for any code path that does not explicitely return a value".
The key to understanding this is that the compiler reforms methods that constitute iterators, to code that does no longer have uninitialized return values. See C# standard chapter 10.4.4.1 for an example.
Related: https://stackoverflow.com/a/9631242/1132334
another words, you are in agreement with hans?
– l--''''''---------''''''''''''
Nov 23 at 1:36
we both are in agreement with the specification. only that Hans obviously knows it by heart, and I have to look it up.
– dlatikay
Nov 23 at 1:45
add a comment |
This is an exception in connection with the IEnumerable
iterator pattern and the yield return
keyword. In this case, the compiler constructs its state machine for the iterator runtime, and does not apply the same set of path coverage as it does with linear methods.
The semantics goes, "an iterator that does not produce, is empty, and this is at the same time a valid substitution for any code path that does not explicitely return a value".
The key to understanding this is that the compiler reforms methods that constitute iterators, to code that does no longer have uninitialized return values. See C# standard chapter 10.4.4.1 for an example.
Related: https://stackoverflow.com/a/9631242/1132334
another words, you are in agreement with hans?
– l--''''''---------''''''''''''
Nov 23 at 1:36
we both are in agreement with the specification. only that Hans obviously knows it by heart, and I have to look it up.
– dlatikay
Nov 23 at 1:45
add a comment |
This is an exception in connection with the IEnumerable
iterator pattern and the yield return
keyword. In this case, the compiler constructs its state machine for the iterator runtime, and does not apply the same set of path coverage as it does with linear methods.
The semantics goes, "an iterator that does not produce, is empty, and this is at the same time a valid substitution for any code path that does not explicitely return a value".
The key to understanding this is that the compiler reforms methods that constitute iterators, to code that does no longer have uninitialized return values. See C# standard chapter 10.4.4.1 for an example.
Related: https://stackoverflow.com/a/9631242/1132334
This is an exception in connection with the IEnumerable
iterator pattern and the yield return
keyword. In this case, the compiler constructs its state machine for the iterator runtime, and does not apply the same set of path coverage as it does with linear methods.
The semantics goes, "an iterator that does not produce, is empty, and this is at the same time a valid substitution for any code path that does not explicitely return a value".
The key to understanding this is that the compiler reforms methods that constitute iterators, to code that does no longer have uninitialized return values. See C# standard chapter 10.4.4.1 for an example.
Related: https://stackoverflow.com/a/9631242/1132334
edited Nov 23 at 1:44
answered Nov 23 at 1:34
dlatikay
6,22521848
6,22521848
another words, you are in agreement with hans?
– l--''''''---------''''''''''''
Nov 23 at 1:36
we both are in agreement with the specification. only that Hans obviously knows it by heart, and I have to look it up.
– dlatikay
Nov 23 at 1:45
add a comment |
another words, you are in agreement with hans?
– l--''''''---------''''''''''''
Nov 23 at 1:36
we both are in agreement with the specification. only that Hans obviously knows it by heart, and I have to look it up.
– dlatikay
Nov 23 at 1:45
another words, you are in agreement with hans?
– l--''''''---------''''''''''''
Nov 23 at 1:36
another words, you are in agreement with hans?
– l--''''''---------''''''''''''
Nov 23 at 1:36
we both are in agreement with the specification. only that Hans obviously knows it by heart, and I have to look it up.
– dlatikay
Nov 23 at 1:45
we both are in agreement with the specification. only that Hans obviously knows it by heart, and I have to look it up.
– dlatikay
Nov 23 at 1:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439655%2fwhy-does-the-compiler-not-complain-about-not-all-paths-returning%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@DavidG exactly! and my signature is promising an
IEnumerable<string>
return value, not avoid
!– l--''''''---------''''''''''''
Nov 23 at 1:27
1
That is the nature of yield return. Check example from Microsoft. docs.microsoft.com/en-us/dotnet/csharp/language-reference/… If exponent is 0, it is the same as yours.
– wannadream
Nov 23 at 1:29
3
Iterators march to a different drummer. Not returning anything is just fine, it returns an empty iterator.
– Hans Passant
Nov 23 at 1:31
@HansPassant very nice explanation, but where does it say that?
– l--''''''---------''''''''''''
Nov 23 at 1:32
2
The C# language specification, chapter 10.4.4.1. It doesn't exactly yell it out.
– Hans Passant
Nov 23 at 1:36