c-sharp
There are 4 entries for the tag c-sharp

A year ago I had written briefly about my love-affair with the yield keyword. Today a question was posed to me and the follow-up discussion was interesting enough to me to warrant a quick post. If you're returning an IEnumberable<T> from a method that reads from a DataReader, is it bad to use yield? My concern is calling a long-running method while looping over the items returned from the method – won’t this keep the SQL connection open longer? Also what if an exception happens while looping, will my reader still get closed? His...

I saw the following question asked earlier today -- the only context given was the code itself. Can anyone tell me what’s wrong with this Dim min As Integer = Integer.Parse(leavingTimeTextBox.Text.Substring(leavingTimeTextBox.Text.IndexOf(":") + 1, leavingTimeTextBox.Text.Length) -1 )? it shows me an exception index out of range exception: length and index must be within the range of the string, parameter name: length  so its five characters and on debug time : index is 2 so I'm starting from index 3 to length which is 5 -1 "4" It was clear that he looking to parse some sort of pre-defined time format, but...

This post was spawned as I was reviewing the latest Oxite source code on CodePlex. I’ve been reading any source code I could get my hands on lately looking for inspiration to cure my “winter coding boredom.” While it isn’t winter yet, it is fast approaching, which means less outdoors time and more computer time. I try to blog more, update my open source projects with a new release, and with any luck begin a new project worth getting passionate about. Today I'm going to hit the ground running with a short tip, again, on the yield keyword. The following code...

This was one of the first extension methods I wrote when C# 3.0 arrived, since I just stumbled across it on an older project I figured I might as well post it, if for nothing else but future reference. One downside to be aware of if you choose to use this method, is that it will not project the results on a IQueryable provider like LINQ to SQL, so please be aware the conversion will be done on the client side. The Code public static class DelimitedStringExtensions { public static string DefaultDelimiter = ", "; ///...