Enums in C# - use sbyte

Author: DeVoid
08 14th, 2008

C# Code Specification:

The following example declares an enum type named Alignment with an underlying type of sbyte.

enum Alignment: sbyte
{
Left = -1,
Center = 0,
Right = 1
}

When you use enumerations in C# - you easy can declare new values as sbyte. Standart type of variable is int, but you can use and sbyte type.



08 10th, 2008

If you need that the program was started an only to one copy - can take advantage of such simple and useful class:

public class SingleInstance
{
private bool firstInstance = false;

public bool FirstInstance
{
get { return firstInstance; }
}

public SingleInstance()
{
Mutex mutex=null;
try
{
mutex = Mutex.OpenExisting("ProgramName");
}
catch (WaitHandleCannotBeOpenedException e)
{
firstInstance = true;
}

if (mutex == null)
{
mutex = new Mutex(false, "ProgramName");

GC.KeepAlive(mutex);
}
}
}

Now, we need edit Program.cs like here:

[STAThread]
static void Main()
{
SingleInstance single = new SingleInstance();

if (single.FirstInstance)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}

Now the program will be started only in one copy. A code works on the different versions of Windows - including Vista.



07 29th, 2008

If you want create the mod_rewrite analogue and use links as mysite/user/DeVoid or send an user on other page - use web.config option urlMappings in ASP.NET:

<configuration>
<system.web>
<urlMappings enabled="true">
<add
url="~/Article28.aspx"
mappedUrl="~/MyNewBestArtile.aspx"/
>
<urlMappings>
</system.web>
</configuration>

Using urlMappings you will be able to do your site on ASP.NET more attractive for an user



Welcome to Community!

Author: admin
07 19th, 2008

I created this site for programmers, my colleagues, could publish here the ideas, divided experience, to communicate between itself, help novices. Every visitor which will be registered - can write in blog, leave a comment, see the users profiles. I hope you will find here much interesting.