foreach vs someList.ForEach(){}

There are apparently many ways to iterate over a collection. Curious if there are any differences, or why you’d use one way over the other. First type: Other Way: I suppose off the top of my head, that instead of the anonymous delegate I use above, you’d have a reusable delegate you could specify…

‘do…while’ vs. ‘while’

If you always want the loop to execute at least once. It’s not common, but I do use it from time to time. One case where you might want to use it is trying to access a resource that could require a retry, e.g.

Regex for numbers only

Use the beginning and end anchors. Use “^\d+$” if you need to match more than one digit. Note that “\d” will match [0-9] and other digit characters like the Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩. Use “^[0-9]+$” to restrict matches to just the Arabic numerals 0 – 9. If you need to include any numeric representations other than just digits (like decimal values for starters), then … Read more

Get current folder path

You should not use Directory.GetCurrentDirectory() in your case, as the current directory may differ from the execution folder, especially when you execute the program through a shortcut. It’s better to use Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); for your purpose. This returns the pathname where the currently executing assembly resides. While my suggested approach allows you to differentiate between the executing assembly, the entry assembly or … Read more

ASP.NET Core Dependency Injection error: Unable to resolve service for type while attempting to activate

To break down the error message: Unable to resolve service for type ‘WebApplication1.Data.BloggerRepository’ while attempting to activate ‘WebApplication1.Controllers.BlogController’. That is saying that your application is trying to create an instance of BlogController but it doesn’t know how to create an instance of BloggerRepository to pass into the constructor. Now look at your startup: That is saying whenever a IBloggerRepository is required, create a BloggerRepository and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)