Jump to content

Creating and Importing Libary

Go to solution Solved by madknight3,

If you haven't already done so, create a Class Library project in your solution and add that file. Then you can add a reference to that Class Library project in your other projects. When you've got the reference added, you can import the namespace with using Complex_Class; and use the classes in that namespace in your code.

 

Here's a video demonstration

Hello guys I was looking into making a Libary named Complex Class, so I do not need to copy and paste the whole class or rewrite it. But now I do not know how to create it or Import it. I am using Visual Studios 2014.

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Complex_Class{    public class Complex    {        private double mRe, mIm, mB, mW;        private void KarthToPolar()        {            mB = Math.Sqrt((mRe * mRe) + (mIm * mIm));            mW = Math.Atan2(mIm, mRe);        }        private void PolarToKarth()        {            mRe = mB * Math.Cos(mW);            mIm = mB * Math.Sin(mW);        }        public double Re        {            get            {                return mRe;            }            set            {                mRe = value;                KarthToPolar();            }        }        public double Im        {            get            {                return mIm;            }            set            {                mIm = value;                KarthToPolar();            }        }        public double B        {            get            {                return mB;            }            set            {                mB = value;                PolarToKarth();            }        }        public double W        {            get            {                return mW;            }            set            {                mW = value;                PolarToKarth();            }        }        public static Complex operator +(Complex lhs, Complex rhs)        {            var add = new Complex();            add.Re = lhs.mRe + rhs.mRe;            add.Im = lhs.mIm + lhs.mIm;            return add;        }        public static Complex operator -(Complex lhs, Complex rhs)        {            var subb = new Complex();            subb.mRe = lhs.mRe - rhs.mRe;            subb.mIm = lhs.mIm - rhs.mIm;            return subb;        }        public static Complex operator /(Complex lhs, Complex rhs)        {            var div = new Complex();            div.mB = lhs.mB / rhs.mB;            div.mW = lhs.mW - lhs.mW;            return div;        }        public static Complex operator *(Complex lhs, Complex rhs)        {            var mul = new Complex();            mul.mB = lhs.mB * rhs.mB;            mul.mW = lhs.mW + rhs.mW;            return mul;        }        public override string ToString()        {            return string.Format("({0} + {1}i)", this.mRe, this.mIm);        }    }}

Hope you guys can help me.

Link to comment
https://linustechtips.com/topic/259689-creating-and-importing-libary/
Share on other sites

Link to post
Share on other sites

If you haven't already done so, create a Class Library project in your solution and add that file. Then you can add a reference to that Class Library project in your other projects. When you've got the reference added, you can import the namespace with using Complex_Class; and use the classes in that namespace in your code.

 

Here's a video demonstration

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×