Wednesday, April 25, 2012

NaN

Sometimes, when using double variables, in some expressions you may get "NaN" values.
In order to determine if the value is NaN, you can use the following expression:
if(double.NaN.CompareTo(variable)==0)
{
   // Do something;
}

Wednesday, April 11, 2012

Checking and creating a directory

Almost all applications need to write "stuff" to a certain directory. The directory can store images, configuration files, databases,... whatever,...
So here in this example we'll create a "Temp" directory in the application path.

public String determineTempDirectory()
{
     String TempDirectory;


     TempDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
     TempDirectory+="\\Temp";


     if(!System.IO.Directory.Exists(TempDirectory))
          {
               System.IO.Directory.CreateDirectory(TempDirectory);
          }


     return TempDirectory;
}


So, by dissecting this code, we can see that what this function does is to return the path of a "Temp" directory, located on the same location as the application. The function checks if the "Temp" directory already exists and if doesn't then, creates it.

The purpose

Hi everyone

I start this blog as a way to help C# developers to find solutions to their problems on their day-to-day tasks.As we all know, when having dificulties on a certain task, its a lot easier to find the solution on the internet than to keep hitting the head against the wall, killing brain cells.
They might be usefull for another time, when no one knows the sollution to the
problem.


I hope to help you all, but you can also help others, by posting
comments on this blog.

Please, take note that every case presented here may work in some cases and not work in other cases. You should allways be aware of what you're doing and what consequencies the solutions presented here might have on your sistem (software and/or hardware). Although my intentions are only of helping others, not to harm anyone, you should understand that it's impossible to find solutions that work for everyone and ensure that those sollutions won't harm the system for some reason.

Enjoy and take advantage