method overloading vs optional parameter in C# 4.0 [duplicate]

One good use case for ‘Optional parameters’ in conjunction with ‘Named Parameters’ in C# 4.0 is that it presents us with an elegant alternative to method overloading where you overload method based on the number of parameters. For example say you want a method foo to be be called/used like so, foo(), foo(1), foo(1,2), foo(1,2, … Read more

C# operator overload for `+=`?

Overloadable Operators, from MSDN: Assignment operators cannot be overloaded, but +=, for example, is evaluated using +, which can be overloaded. Even more, none of assignment operators can be overloaded. I think this is because there will be an effect for the Garbage collection and memory management, which is a potential security hole in CLR … Read more

Moq, SetupGet, Mocking a property

ColumnNames is a property of type List<String> so when you are setting up you need to pass a List<String> in the Returns call as an argument (or a func which return a List<String>) But with this line you are trying to return just a string input.SetupGet(x => x.ColumnNames).Returns(temp[0]); which is causing the exception. Change it … Read more

Check if list contains any of another list

You could use a nested Any() for this check which is available on any Enumerable: bool hasMatch = myStrings.Any(x => parameters.Any(y => y.source == x)); Faster performing on larger collections would be to project parameters to source and then use Intersect which internally uses a HashSet<T> so instead of O(n^2) for the first approach (the … Read more

No Main() in WPF?

The Main() method is created automatically. If you want to provide your own you have to (tested in VS2013, VS2017 and VS2019): Right-click App.xaml in the solution explorer, select Properties Change ‘Build Action’ to ‘Page’ (initial value is ‘ApplicationDefinition’) Then just add a Main() method to App.xaml.cs. It could be like this: [STAThread] public static … Read more

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