Accessing variables from other namespaces

Leave a Comment
Normally, variables don't live in a namespace alone, they live inside another class that could be in another namespace. If you need to access a variable in another class (in another namespace), your other class needs to expose the variable somehow. The common practice for this is to use a public Property (static if you only need access to that variable) for the variable.

namespace My.Namespace
{
    public class MyClassA
    {
        public void MyMethod()
        {
            // Use value from MyOtherClass
            int myValue = My.Other.Namespace.MyOtherClass.MyInt;
        }
    }
}

namespace My.Other.Namespace
{
    public class MyOtherClass
    {
        private static int myInt;
        public static int MyInt
        {
            get {return myInt;}
            set {myInt = value;}
        }

        // Can also do this in C#3.0
        public static int MyOtherInt {get;set;}
    }
}

MySQL: Reorder/Reset auto increment primary key?

Leave a Comment
To reset the IDs of my User table, I use the following SQL query. It's been said above that this will ruin any relationships you may have with any other tables.


ALTER TABLE `users` DROP `id`;
ALTER TABLE `users` AUTO_INCREMENT = 1;
ALTER TABLE `users` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;