File to be used as a library assembly 2 : DLL Library « Language Basics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Language Basics » DLL Library 




File to be used as a library assembly 2

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

//  Circle.cs -- File to be used as a library assembly
//
//               Compile this file with the following command line:
//                   C:>csc /t:module Circle.cs
using System;

namespace nsCircle
{
// A structure to define a Cartesian point.
    public struct POINT
    {
        public POINT (int x, int y)
        {
            cx = x;
            cy = y;
        }
        public int  cx;
        public int  cy;
        public override string ToString()
        {
           return (String.Format ("(" + cx + ", " + cy + ")"));
        }
    }
    public class clsCircle
    {
// Two constructors to define the circle.
        public clsCircle (double radius, POINT center)
        {
            m_Center = center;
            m_Radius = radius;
        }
        public clsCircle (double radius, int cx, int cy)
        {
            m_Center.cx = cx;
            m_Center.cy = cy;
            m_Radius = radius;
        }
        public clsCircle ()
        {
            m_Center.cx = 0;
            m_Center.cy = 0;
            m_Radius = 0;
        }
        public double Radius
        {
            get {return (m_Radius);}
            set {m_Radius = value;}
        }
        public POINT Center
        {
            get {return (m_Center);}
            set {m_Center = value;}
        }
// Fields to contain circle data.
        POINT m_Center;
        private double m_Radius;

// Constants to make life easier
        private const double pi = 3.14159;
        private const double radian = 57.29578;
// Return the area of the circle
        public double Area
        {
            get {return (m_Radius * m_Radius * pi);}
        }
// Return the diameter of the circle
        public double Diameter
        {
            get {return (* m_Radius);}
        }
// Return the coordinates of a point on the circle at a given angle.
        public POINT PointOnCircle (double degrees)
        {
            POINT pt;
            double fAngle = degrees / radian;
// Compute the x position of the point
            pt.cx = (int)((doublem_Radius * Math.Cos (fAngle0.5);
// Compute the y position of the point
            pt.cy = (int)((doublem_Radius * Math.Sin (fAngle0.5);
            return (pt);
        }
// Return the area of a slice determined by a given angle.
        public double AreaOfSlice (double degrees)
        {
            double fAngle = degrees / 57.29578;
            return (Area * fAngle / (* pi));
        }
    }
}



// Geom.cs -- Demonstrates using an assembly.
//
//            Build this program and the Circle assembly using
//            the following command sequence:
//                C:>csc /t:module Circle.cs
//                C:>sn -k Circle.snk
//                C:>al /keyfile:Circle.snk /version:1.0.0.0 /out:Circle.dll Circle.NetModule
//                C:>gacutil /i Circle.dll
//                C:>csc /r:circle.dll Geom.cs
//
using System;
using nsCircle;

namespace nsGeometry
{
    class clsMain
    {
        static public void Main ()
        {
            double angle = 32.6;
// Create an instance of the circle class.
            clsCircle circle = new clsCircle (42000);
// Get the point on the circle at the angle.
            POINT pt = circle.PointOnCircle (angle);
// Show the total area of the circle.
            Console.WriteLine ("The area of the circle is " + circle.Area);
// Show the point.
            Console.WriteLine ("The point on the circle is at " + pt);
// Show the area of the slice between 0 degrees and the angle.
            Console.WriteLine ("The area of the slice is " +
                                circle.AreaOfSlice (angle));
        }
    }
}


           
       














Related examples in the same category
1.File to be used as a library assembly
2.Loading Assemblies: Making it Dynamic
3.Creates a library assembly
4.Calling Native DLL FunctionsCalling Native DLL Functions
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.