File to be used as a library assembly : 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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Language Basics » DLL LibraryScreenshots 
File to be used as a library assembly

/*
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:library 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.
//
//            Compile this program with the following command line:
//                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
2.Loading Assemblies: Making it Dynamic
3.Creates a library assembly
4.Calling Native DLL FunctionsCalling Native DLL Functions
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.