Monday, 24 September 2012

C# - Skeleton of a C# Program

  1. C# program can consist of one or more files (cs)
  2. Each file can contain zero or more namespaces
  3. Each namespace can contain types such as classes, structs, interfaces, enumerations, delegates, other namespaces

/*****************************************/
// A skeleton of a C# program
using System;
namespace YourNamespace
{
    class YourClass
    {
    }
    struct YourStruct
    {
    }
    interface IYourInterface
    {
    }
    delegate int YourDelegate();
    enum YourEnum
    {
    }
    namespace YourNestedNamespace
    {
        struct YourStruct
        {
        }
    }
    class YourMainClass
    {
        static void Main(string[] args)
        {
            //Your program starts here...
        }
    }
}
/*****************************************/

VC++ - LNK1000 error when incrementally linking

Error Description from Microsoft
http://support.microsoft.com/kb/948127

Download Hotfix from Microsoft
http://archive.msdn.microsoft.com/KB948127/Release/ProjectReleases.aspx?ReleaseId=871

C# - Create DLL Project

New Project
  • Project Types = Visual C#
  • Templates = Class Library


Project Properties
  • Output Type = Class Library
  • Output Path = "bin\Debug\"
 

Compile and Build => dll file will be created in output path.

Example:
  1. Type the following in the Class1.cs
  2. /**********************************/
    namespace MathFunctions
    {
        public class AddClass
        {
            public static int Add(int a, int b)
            {
                return (a + b);
            } 
        }
    }
    /**********************************/
  3. After compile and build, MathFunctions.dll file is created in output bin. (MathFunctions.dll file name is based on Assembly name in Project Properties)
  4. User can then use the dll by
    • Add reference the MathFunctions.dll
    • Using MathFunctions;
  5. Then "AddClass" can now be use in the user project.
External Link
http://www.codeguru.com/csharp/csharp/cs_misc/dllsandexecutables/article.php/c4239/Creating-and-Using-C-DLLs.htm