Can you call Directory.GetFiles() with multiple filters?

For .NET 4.0 and later, var files = Directory.EnumerateFiles(“C:\\path”, “*.*”, SearchOption.AllDirectories) .Where(s => s.EndsWith(“.mp3”) || s.EndsWith(“.jpg”)); For earlier versions of .NET, var files = Directory.GetFiles(“C:\\path”, “*.*”, SearchOption.AllDirectories) .Where(s => s.EndsWith(“.mp3”) || s.EndsWith(“.jpg”)); edit: Please read the comments. The improvement that Paul Farry suggests, and the memory/performance issue that Christian.K points out are both very important.

Why are C# 4 optional parameters defined on interface not enforced on implementing class?

UPDATE: This question was the subject of my blog on May 12th 2011. Thanks for the great question! Suppose you have an interface as you describe, and a hundred classes that implement it. Then you decide to make one of the parameters of one of the interface’s methods optional. Are you suggesting that the right … Read more

Could you explain STA and MTA?

The COM threading model is called an “apartment” model, where the execution context of initialized COM objects is associated with either a single thread (Single Thread Apartment) or many threads (Multi Thread Apartment). In this model, a COM object, once initialized in an apartment, is part of that apartment for the duration of its runtime. … Read more

How to print the current Stack Trace in .NET without any exception?

Have a look at the System.Diagnostics namespace. Lots of goodies in there! System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace(); This is really good to have a poke around in to learn what’s going on under the hood. I’d recommend that you have a look into logging solutions (Such as NLog, log4net or the Microsoft patterns and practices … Read more

Use of Finalize/Dispose method in C#

The recommended IDisposable pattern is here. When programming a class that uses IDisposable, generally you should use two patterns: When implementing a sealed class that doesn’t use unmanaged resources, you simply implement a Dispose method as with normal interface implementations: public sealed class A : IDisposable { public void Dispose() { // get rid of … Read more

How to declare a local variable in Razor?

I think you were pretty close, try this: @{bool isUserConnected = string.IsNullOrEmpty(Model.CreatorFullName);} @if (isUserConnected) { // meaning that the viewing user has not been saved so continue <div> <div> click to join us </div> <a id=”login” href=”https://stackoverflow.com/questions/6601715/javascript:void(0);” style=”display: inline; “>join here</a> </div> }

When & why to use delegates? [duplicate]

A delegate is a reference to a method. Whereas objects can easily be sent as parameters into methods, constructor or whatever, methods are a bit more tricky. But every once in a while you might feel the need to send a method as a parameter to another method, and that’s when you’ll need delegates. using … Read more

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