Here is something neat I found out.

Say you are writing an application and one of the requirements is to allow File System search. You could always start using loops and such. I thought to myself why not do it in LINQ? I played around with it and in fact it is not so hard.

Lets see how it is done. Here is method that allows finding a specific file name in side a directory.

   1: private List SearchFilesByName(string DirectoryPath, string FileName) 
   2: { 
   3:     return (from file in new DirectoryInfo(DirectoryPath).GetFiles() 
   4:             where file.Name == FileName select file).ToList(); 
   5: }

Basically we Query the FileInfo[] which is returned from the GetFiles() method and compare the file name.


Continue Reading...

The twelfth post of the series of programming job interview challenge is out, 28 readers provided answers to job interview challenge #11. I have to admit that I probably failed explaining what I was looking for in challenge #11, because I asked you to provide the best algorithm in both manners: performance and memory. What I really meant is that performance is most important but don’t neglect the memory issue. Due to my little “embarrassing failure”, there are two groups of correct answers - the performance oriented and the memory oriented.

The correct answer which I was looking for (best at performance) as Alex, the first one to provide a detailed solution (its two times in a row), wrote:


Continue Reading...

Hi

In my previous article I talked about why SortedList is not a good option to use if you need a sorted collection with keys that are not unique. Today I will show you how to use a regular generic List<T> to store sorted items. You basically have 2 options.

IComparable Interface

this means that you will have to make your stored class Implement the IComparable Interface. Here is an example:


Continue Reading...

This one could be easily become one of the Job Interview Questions we publish here at Dev102.com, but I decided to write a “regular” post about this issue because it is an important concept and not a just a puzzle or a brain teaser. Take a look at the following code, can you tell what will the output be?

public class BaseType
 {
     public BaseType()
     {
         Console.WriteLine("Call base ctor.");
         DoSomething();
     }

     public virtual void DoSomething()
     {
         Console.WriteLine("Base DoSomething");
     }
 }

 public class DerivedType : BaseType
 {
     public DerivedType()
     {
         Console.WriteLine("Call derived ctor.");
     }

     public override void DoSomething()
     {
         Console.WriteLine("Derived DoSomething");
     }
 }

 public class MainClass
 {
     public static void Main()
     {
         DerivedType derived = new DerivedType();
         Console.ReadLine();
     }
 }

The output of this program is:


Continue Reading...

Hi all
It seems that the RSS Error has been fixed and http://feeds.feedburner.com/Dev102feed is working again.
If you have subscribed to the old feed (during the past couple of hours) please resubscribe to the Feedburner one.
Thanks and sorry again
Amit


Continue Reading...

Hi all
We are having some RSS Feed errors our feed is OK but it seems that FeedBurner can’t find it. If anyone knows how to solve this, help will be welcomed.
This is the error we are getting
Bang! Kapowww! Krakkk!
(FeedBurner encountered an error while trying to bring you this feed and is now keeping its head [...]


Continue Reading...

The eleventh post of the series of programming job interview challenge is out. 75 readers provided answers to job interview challenge #10 and most of them had the correct solution. The correct answer as Alex, the first one to provide a detailed solution, wrote:

Here’s an O(N) solution:

Have one variable that stores the sum of all the values. Iterate through the list to add all numbers to the variable, which for simplicity I will call “listSum”.

Now, take the theoretical sum of all numbers between 1…n+1: This can be computed in O(1), as the sum of numbers up to N is n(n+1)/2: So for numbers up to n+1, it’d be (n+1)(n+2)/2 (for instance, if the array is of size 9, we’d do 10*(11)/2, or a theoretical sum of 55). Call this sum “allSum”.

The missing number will be the result of computing “allSum - listSum”.

O(N)complexity, with only two tracking variables.


Continue Reading...

Another month has come to an end and an interesting month it was!

The high light of the month was getting one of our articles on the front page of stumbleupon which drove almost 30000 visitors to dev102!!! That article was not a programming article but in fact a humorous one about company logos. That definitely gave a boost to our Page Views and Visits Stats but damaged the Page Views/Visits, Bounce Rate and Time on page. During that time dev102 crashed several times so we decided to install the WP-SuperCache plugin which removes allot of load from the server.
Read more about caching you WebSite here.

Blogging Idol We are also taking part in the blogging Idol contest Arraigned by Daniel from DailyBlogTips

The winner of the contest is the one who manages to add as many Subscribers as possible to his RSS feed over one month.

So get your friends in and help us Win it!


Continue Reading...

The other day I wan in the need of a sorted collection. I found that there are 2 sorted collections available. SortedDictionary and SortedList. Now let me ask you, what do you think is the difference? Well, my first though was that they are the same except for the keys, which in SortedDictionary have to [...]


Continue Reading...

It is very common to use resource files in .Net applications when you need to store some data in a XML file. I usually use .resx files as string tables in order to avoid hard coded strings in my code. Two months ago, we published a post about a free tool which helps to extract hard coded strings to resource files. Notice that when you add a resource file, there is an automatically generated class with properties issued from the resources elements, so you can call this class properties instead of using the ResourceManager. The only problem with this class is that its properties are marked as internal and thus can’t be accessed externally (from other assemblies).


Continue Reading...