Sometimes we are using the same patterns of code over and over again. Those of us who are lazy (but smart) will create their own code snippets, if you are not familiar with this subject, read about how to create code snippets easily. But what if we need to create lots of classes with the same pattern? Code snippets may not be enough because they lack of some functionality which is needed to achieve our goal. Consider the following code:
abstract class FourWheelsVehicle : IVehicle
{
abstract public double MaxVelocity { get; }
abstract public string Manufacturer { get; }
abstract public double Price { get; }
abstract public int YearManufactured { get; }
virtual public int NumberOfWheels
{
get { return 4; }
}
}
An abstract class called FourWheelsVehicle implements the IVehicle interface (which is not presented here because it is not important for our matter). Our task is to create classes which represent each and every existing 4 wheels vehicle, there is a lot of work to do, a huge amount of work. So, I started by implementing Mazda6 class:
Continue Reading...
Here is something nice I have found while wandering around the Internet. We all know jQuery, jQuery is a Framework written in JavaScript which makes client side and DOM work much easier and faster. If you don’t know it yet, be sure to check it out, it makes Web Developers life easy on the web. Shahar wrote a great article about Calling ASP.NET WebMethod with jQuery so check it out.
Continue Reading...
The thirteen post of the series of programming job interview challenge is out, Only 13 comments with answers were provided to job interview challenge #12. This is a small amount comparing to the previous challenges, but I realize and understand that it was language specific and not very trivial challenge…
Jason Kikel was the first one to solve the question, and here is his short answer:
UnmanagedClass is referencing an address on ManagedClass without pinning it. The ManagedClass instance needs to be pinned so the GC won’t move it to another location during a collection.
Continue Reading...
Today, in many applications there is a need to know and use HTML. And if you are a Web applications programmer you probably should know HTML :).
The question is do you know all the HTML tags? Do you know exactly how they work and what each tag does? And the most important of all, how each tag acts in each browser?
There are hundreds of books, articles, WebSites, posts, blogs and manuals that claim to "teach" you HTML. I on the other hand think that there is no experience like hands on experience so I wanted to introduce you to HTML Playground . This is one of my favorites sites for HTML.
Continue Reading...
Hi all
As you all remember in my article about Custom WPF Context Menu I mentioned that my WPF Binding Converter was a singleton, and I promised to tell you why, so here comes the 3 ways I know of using WPF Binding Converters. We will start from the worst (in my opinion) and move on the the best.
To start off here is the Binding Converter:
Continue Reading...
A week or two ago, I read an interesting article in Coding Horror called The Problem With Code Folding. Let me quote the beginning of this post:
When you join a team, it’s important to bend your preferences a little to accommodate the generally accepted coding practices of that team. Not everyone has to agree on every miniscule detail of the code, of course, but it’s a good idea to discuss it with your team and decide on overall approaches and philosophy beforehand. It promotes team harmony, and more than that, it’s just common courtesy. As they say, when in Rome, do as the Romans do.
Jeff Atwood is talking about the fact that it is important to obey the coding conventions and practices of your team. Every one of us as its own preferences but as a team we need to have some rules, we all should work with the team, not against it. I must admit that I totally agree with Jeff’s attitude, no questions about it.
But, in addition to what was said before, Jeff continues:
Still, there are some coding preferences people may feel.. strongly.. about. If that’s the case, try to clear the air and address those strong preferences up front, as early as possible. Don’t let them simmer. For me, the use of #region is one of those things. I tried to make myself clear in this twitter message: No, I will not use #regions. And no, I DO NOT NEGOTIATE WITH TERRORISTS. Shut up.
I am not going to talk about the #regions issue, but to have my own say about another coding preference:
Continue Reading...
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...