6/27/2006 1:17:19 PM
This task might seem trivial to most but I figured I would post for those that don`t know how to create "Global" classes in C#. Global methods and variables are not supported in C# but you can place all of your common methods and variables within a class file and access them throughout your application. Connection strings and log updaters are perfect candidates for this. I ran into a couple of questions about this while cruising Google Groups.
Foo.cs
using
System;using
System.Data;using
System.Data.SqlClient;using
System.Configuration;
namespace
Foo{
public abstract class Global
{
public static SqlConnection connection()
{
SqlConnection cn = new SqlConnection(...)
return cn;
}
public static String stupid()
{
return "stupid";
}
}
}
Bar.cs
using
System;using
System.Data;using
System.Data.SqlClient;using
System.Configuration;
namespace
Bar{
public class Default_Page
{
SqlConnection cn = Foo.Global.cn();
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write(Foo.Global.Stupid());
}
}
}
C#,
Code,
Programming
