Answer by user2023861 for Find the largest odd number (follow-up code)
You can do this without storing the inputs and looping through them afterwards. You only need to remember whether or not an odd number was entered and which one is the largest. My Python is weak so...
View ArticleAnswer by user2023861 for Stack implementation in C#
Going off your question about pushing zeroes onto the stack, another user mentioned that you should keep an index into the stack to remember where to push and pop. I've updated your code only...
View ArticleAnswer by user2023861 for Demonstration of inheritance with some shapes
Your code doesn't benefit from the use of inheritance. You can remove all references to IShape without losing anything. If you had an illustrator class that accepted IShape objects, then you'd have...
View ArticleAnswer by user2023861 for Implementing a thread safe log class with simple...
A comment about your Log(string) method. The lock keyword is just syntactic sugar for a call to the Monitor class. See here. Here is what lock becomes:bool lockWasTaken = false;var temp = obj;try {...
View ArticleAnswer by user2023861 for Converting a 12 hour time string to a 24 hour time...
Here's how to parse dates and times using built-in .Net libraries:static void Main(){ string strTime = "01:00:10AM"; DateTime time; if (DateTime.TryParseExact(strTime, "hh:mm:sstt", null,...
View ArticleAnswer by user2023861 for Simple foreach adding to a list
Just use the Concatenation method. That's really what you're doing. You can also use the List constructor that takes an IEnumerable.var soonestDrawDateModel = new List<SoonestDrawDateModel>(...
View ArticleAnswer by user2023861 for FizzBuzz in T-SQL
Here's a pretty succinct way to do it. I use a recursive common-table expression to fill in a table of integers from 1 to 100.with tbl (idx)as( select 1 union all select idx + 1 from tbl where idx <...
View ArticleAnswer by user2023861 for Top Python badged users from NYC
In my opinion, your where clauses take up too much vertical space and can be made more maintainable. Compare what you have with this:where b.name = N'python' and b.class = 3 -- 1 is gold, 2: silver, 3:...
View ArticleAnswer by user2023861 for Puzzle Packing Box Z optimisation
This is not an answer about your algorithm but a couple of performance comments that wouldn't fit in the ongoing comment discussion.I'm guessing that your deeply nested loops are taking up the bulk of...
View ArticleAnswer by user2023861 for Swapping characters pairs in a string
Finally, an excuse to use the Zip extension method:private static string StringSwap2(string stringToSwap){ if ((stringToSwap.Length % 2).Equals(1)) { stringToSwap += ""; } var evens =...
View ArticleAnswer by user2023861 for Parsing data from text with repeating blocks
Your methods are too big and are doing too much. ParseDebugListResponse is responsible for finding the backend boundaries, splitting the response into backend objects, determining what each line is,...
View ArticleAnswer by user2023861 for A more efficient way of extracting a name from a...
Here's a simple Regex to pull out the CN value:CN=([^,]*),You can use this C# code to get the value:string CN = Regex.Replace(input, @"CN=([^,]*),", "$1");Here are the important points:I'm assuming you...
View ArticleAnswer by user2023861 for Extracting Excel data out of an existing Excel file
Two quick points:First: Make sure you're cleaning up your Interop objects properly. It's not easy. See here for more. The first answer has good advice: never use two dots with COM objects. Many of your...
View ArticleAnswer by user2023861 for Function to compare objects based on type enums
Your outer switch statement has 9 cases (and one default). If you take advantage of polymorphism, you can split this out into 9 classes with no need for some default handler. Here's some information...
View ArticleAnswer by user2023861 for Convert XML to CSV
You can do it with a series of Regex.Replaces:// 1) Replace closing and opening tags with commas.// Include quotes in case any values have commas in them.var result = Regex.Replace(input,...
View Article