We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution
Learn MoreI am currently working on a SaveAs feature to some special file formats, those files are very very big. Before actually saving the file, I need to compute its anticipated size and compare it with the free disk space to see if there is enough storage for that operation. After searching a bit about how to get the free disk space, I came across the solution which uses the System.Management namespace. This namespace provides access to a rich set of management information about the system, devices, and applications instrumented to the WMI infrastructure. But, what the hell is WMI?
WMI is Windows Management Instrumentation and is part of the Windows operating system that provides management information and control. WMI provides extensive instrumentation to accomplish almost any management task and help us obtain information about our system. Applications and services can query for interesting management information such as how much free space is left on the disk, what is the current CPU utilization, which database a certain application is connected to, and much more, using classes from the System.Management namespace. Here is the MSDN page about the Windows Management Instrumentation.
Let me show you how to query the free disk space using WMI:
Until a couple of years ago, most software applications were released in English. Unfortunately for us the developers, nowadays, many customers require that that the product they purchased, will be localized to a specific language (other than English). I know, for instance, that there is a European law which requires healthcare products to be localized to the European market (starting from 2009 or 2010). Because this article is about how to localize your application using string tables, I recommend you to first read about a free tool which helps you extract hard coded strings to string tables. Don’t go any further before you also read about how to generate public properties for string tables, you must read it.
Setting up a String Table
I assume that you already have some user interface which needs to be localized, I will demonstrate this process with…
Are you familiar with the following C# compilation error: “CS0104: ClassA is an ambiguous reference between Namespace1.ClassA and Namespace2.ClassA“? It happens when your program contains using directives for two namespaces and your code references a name that appears in both namespaces.
Lets work with a concrete example:
Sometimes we need to know the width of a given string in pixels, do you know how to compute it? Before writing some long code, please notice that the .NET framework class library provides such a method. When Googling about this issue, we find the Graphics.MeasureString Method, here is how to use it:
Graphics graphics = this.CreateGraphics(); SizeF textSize = graphics.MeasureString("How long am I?", this.Font);
Nice isn’t it? Well, there is one little problem here, how is the Graphics object created? The written code is a Windows Forms code, so the this is the Form itself. You can’t create the Graphics object by simply allocating it because…
Here is the code which defines a C# EventHandler, as written in the documentation, it represents the method that will handle an event that has no event data:
// Summary: // Represents the method that will handle an event that has no event data. // // Parameters: // sender: // The source of the event. // // e: // An System.EventArgs that contains no event data. [Serializable] [ComVisible(true)] public delegate void EventHandler(object sender, EventArgs e);
So after declaring a specific event:
private event EventHandler OnSomethingHappened;
We need to write a method to raise this event:
We never published a lists of blog posts we liked, so this will be the first time. I gathered some links from my Google Reader shared items, some of those links are old, some are new, but I liked them all. So here is the list of 7 post/articles I recommend:
This is the fifteen post of the series of programming job interview challenge, 37 readers provided an answer to job interview challenge #14. As you can understand from the title, I have a little announcement to make, but lets first head on to last weeks question answers.
This time, Omar was the first one to provide an efficient and correct detailed answer:
Draw a line from the single point (any direction will do).
Count the number of times that this line intersects with lines of the polygon.
An even count (including zero) indicates that the point is outside of the polygon.
An odd count indicates that the point is inside the polygon.
Here is a nice image taken from Jon von Gillern blog post
The fourteenth post of the series of programming job interview challenge is out, 79 comments with answers were provided to job interview challenge #13. We didn’t publish a question last week due to a sever lack of time, so another week is gone and here we are again.
Mark R was the first to provide a correct and detailed answer (which I can quote here):
As you examine each character, classify it as either an opening or closing bracket. If it’s an opening bracket, push it onto a stack. If it’s a closing bracket, pop the top character off of the stack; if the stack was empty, or the character was not the matching open bracket, then return an error. At the end of input, if the stack is empty, you have a legal expression.
C++ has a built-in stack class, so this becomes a trivial problem. I’m not sure about other languages. You could always simulate a stack by appending and deleting characters from the end of a string.
So, in one word, the most efficient answer is use a stack. Here is a nice image which was crafted by David Tchepak in his blog post Brackets, braces, parentheses, and other such creatures:
Have you ever tried using the "Using" statement with a method and not a class?
We all have done the following:
1: using(StreamReader s = new StreamReader(@"c:\Test.txt"))
2: {
3: // Do stuff
4: }
Whether you know it or not, the compiler translates that code to the following:
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:
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd