Welcome to C# Sage, I hope you’ll stick around to enjoy the various posts on C#, Linq and Entity Framework – who know, you might even learn something!
If you’re looking for somewhere you start, you could do worse than checking out some of my recent posts set based linq methods:
- C# String Replace – How to Replace Parts of String in C#Introduction It’s common to have data in one format, but want to change it to another. At a low level, this can often come down to doing string replacements – whether it’s tabs to commas for delimited files, more complicated munges, it’s a useful trick to have up your sleeve. Simplest Replace It doesn’t get …
Continue reading “C# String Replace – How to Replace Parts of String in C#”
- C# Return – How to leave a function/method and return valuesIf you’re a seasoned programmer you’ll know that the c# return statement is used to exit a method, optionally passing a value (a return parameter) back to the calling function. But since you’re here, I’m guessing you’re new enough to C # (or programming in general) to benefit from a deeper dive into what a …
Continue reading “C# Return – How to leave a function/method and return values”
- C# Delay – How to pause code execution in C#Introduction When programming, it is common to want to pause execution for a certain amount of time and most common programming and scripting languages have some form of Sleep command built in to achieve this. For example, when we’ve encountered a problem with a remote resource, it’s common to back-off (pause execution) for a short …
Continue reading “C# Delay – How to pause code execution in C#”
- C# Char to Int – How to convert a Char to an Int in C#Introduction It’s common to pull chars out of string, especially with regular expressions, and need to treat them like a true number. The easiest way to convert a char to in int in C# is: int.Parse(myChar.ToString()). With that said, it’s not always the safest or most efficient method. Here I’ll give you a few different …
Continue reading “C# Char to Int – How to convert a Char to an Int in C#”
- C# List Length – How to get (and set) the Length of a List in C#Introduction On the face of it, this is a really easy one: just use List.Count: Simple Example of getting List Length using List.Count in C# Length Vs Count in C# It’s common to use Arrays before using Lists (at least if you’re as old as I am!) so it often feels natural to use Length. …
Continue reading “C# List Length – How to get (and set) the Length of a List in C#”
- C# Reverse List – How to Reverse a List (and other collections) in C#Introduction I’ve mentioned the Reverse method a couple of times now, so I feel it deserved it’s own post, comparing and contrasting the various implementations. Most recently it came up in one of my technical interviews, and knowing it existed ultimately helped me to land the job, so I want to share this wonderful Linq …
Continue reading “C# Reverse List – How to Reverse a List (and other collections) in C#”
- Linq Interview Questions by Example, how and why!The following question was set for me recently. I had the advantage that my recruiter gave me a heads up on what to expect and I could play around with writing the clearest solution while not under the intense pressure of an interview. I’m in two minds about pre-warning candidates what they should expect in …
Continue reading “Linq Interview Questions by Example, how and why!”
- C# Linq ForEach – How to Linq style loop over items in a ListIntroduction First a quick warning, I have occasionally used this construct in my code, but as part of writing this article I’ve come round to the idea that it’s often a bad idea! That said, to paraphrase Randall Munroe: “The Rules of [coding] are like magic spells. If you never acquire them, then not using …
Continue reading “C# Linq ForEach – How to Linq style loop over items in a List”
- How to Sort a C# Dictionary By Key (and when not to!)Overview Dictionaries in C# are implemented as a Hash Table, this allows near constant time lookups, but is inherently unsorted. To do a one-off extract of the data from a dictionary, sorted by key, you can use the OrderBy Linq method as follows: This is not going to have the best performance, O(n*log(n)), as it …
Continue reading “How to Sort a C# Dictionary By Key (and when not to!)”
- Argo Workflows – Why You Need It!Introduction I’ve been getting down and dirty with Argo Workflows over the past few months as part of my day job. I’ve been evaluating it for use as a workflow automation tool for some risk analytics and I thought I would share some of my experiences. This is the first part in that series explaining …