Quantcast
Channel: User user2023861 - Code Review Stack Exchange
Browsing latest articles
Browse All 35 View Live

Comment by user2023861 on Splitting two ObservableCollections lightning fast

What do you mean "more efficient". Is your code taking a long time to run?

View Article



Comment by user2023861 on Tail-recursive call vs looping for a Poker app

C# doesn't do tail-recursion anyways. You wrote a recursive method, not a tail-recursive method. stackoverflow.com/questions/491376/…

View Article

Comment by user2023861 on Model-View-Presenter Winforms app

Just curious, why Winforms instead of WPF?

View Article

Comment by user2023861 on Algorithm to determine if a string is all unique...

Isn't an array considered a data structure? You're using it as a simple hash table.

View Article

Comment by user2023861 on Take all underlined words, put in Excel column

@BruceWayne, I don't know a VBA way, sorry. It might not be selecting every instance because maybe font sizes are different, or colors, or bold, etc. You can select-all and set the font-size,...

View Article


Comment by user2023861 on Build Excel formulas with string replacements

Your code relieves the horizontal scrolling in the C# code, but not in Excel. If someone wanted to check out the formula in Excel, they'll be scrolling left and right.

View Article

Comment by user2023861 on Build Excel formulas with string replacements

You should consider splitting up the Excel formula. Larger Excel formulas have the same problems that larger C# methods have. They're difficult to maintain. Can you imagine searching this formula for a...

View Article

Comment by user2023861 on Find the repeated elements in a list

+1, scrolled way too far to find this. This is optimal in both runtime and memory usage. This should be the answer

View Article


Comment by user2023861 on Speeding up thousands of string parses

You might see an improvement if you use compiled regular expressions instead of interpreted. Check out this article docs.microsoft.com/en-us/dotnet/standard/base-types/… which shows how to use the...

View Article


Comment by user2023861 on Sum Square Difference, which way is more Pythonic?

unnecessary variables can you explain this point? I think that in general code with more usefully-named variables is easier to maintain than long lines of code like yours

View Article

Comment by user2023861 on C# Blackjack prototype

You spelled "received" wrong

View Article

Answer by user2023861 for Tic Tac Toe in the Console

Why not store moves as a string of 0s and 1s instead of 9 properties? For instance this:_ X __ X OX O _could be represented as:string xmoves = "010010100"string omoves = "000001010"With this scheme,...

View Article

Answer by user2023861 for FizzBuzz Problem Solution

You have four calls to System.out.println(arg). If you want to change your code from printing to the console to writing to a file or a database, you have to change four lines in your code even though...

View Article


Answer by user2023861 for Check if all lotto numbers are covered in input

Your first loop could be simplified:while (ticketNumber != 0) { neededNumbers[ticketNumber - 1] = true; ticketNumber = input.nextInt();}Arrays allow random access, so if you can map your input (a...

View Article

Answer by user2023861 for Census data from file input (text)

Some ideas:You if conditions can be simplified. The following to blocks are logically equivalent. This version is yours with only if statements:if (ageData[i] > 0 && ageData[i] <= 18){...

View Article


Answer by user2023861 for Given two int values, return the one closer to 10

A little math can shorten this. Take the average of the two numbers. If the average is higher than 10, that means the higher number is pulling up the average more than the lower number is pulling it...

View Article

Answer by user2023861 for Matching any certain selection of inputs

I'd suggest that you simplify. Imagine you're a junior programmer and you are asked to edit this abomination (or the one in the accepted answer) in order to add support for inputs of the type 10cm and...

View Article


Answer by user2023861 for String reversal, capitalize vowels, lowercase...

You can make use of char static methods to do a lot of the work for you. Also, there's no need to memorize the ASCII values of vowels. Just use the vowels themselves.static string Problem(string arg){...

View Article

Answer by user2023861 for Sorting a list of first names from a text file

Here's a way to do it in one line of Linq code:int score = System.IO.File.ReadAllLines(ConfigurationManager.AppSettings["LocationOfNamesFile"]) .SelectMany(s => s.Split(',')) .OrderBy(b => b)...

View Article

Answer by user2023861 for SQL query to select most recent version

You can use a sub-query:declare @tbl table ( id INT, effective DATE, points INT)INSERT INTO @tblVALUES (1, '1/1/2015', 123), (1, '2/1/2015', 234), (1, '3/1/2015', 345), (2, '4/1/2015', 123), (2,...

View Article

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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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
Browsing latest articles
Browse All 35 View Live




Latest Images