Exemple #1
0
        public static auto operator /(auto l, string r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                int.TryParse(r, out int result);
                tmp = new auto(l.Int / result);
                break;

            case 1:
                double.TryParse(r, out double result1);
                tmp = new auto(l.Double / result1);
                break;

            case 2:
                string tmpStr = null;
                for (int i = 0; i < l.String.Length; i++)
                {
                    if (!(r.Contains(l.String[i])))
                    {
                        tmpStr += l.String[i];
                    }
                }
                tmp = new auto(tmpStr);
                break;
            }
            return(tmp);
        }
Exemple #2
0
        // subtraction operators
        public static auto operator -(auto l, auto r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                tmp = l - (int)r;
                break;

            case 1:
                tmp = l - (double)r;
                break;

            case 2:
                Console.WriteLine("Operaotor '-' can not be applied to operands of 'string' and 'string'");
                throw new FormatException();
            }
            return(tmp);
        }
Exemple #3
0
        public static auto operator /(auto l, double r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                tmp = new auto(l.Int / (int)r);
                break;

            case 1:
                tmp = new auto(l.Double / r);
                break;

            case 2:
                Console.WriteLine("Operaotor '/' can not be applied to operands of 'string' and 'double'");
                throw new FormatException();
            }
            return(tmp);
        }
Exemple #4
0
        public static auto operator +(auto l, double r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                tmp = new auto(l.Int + (int)r);
                break;

            case 1:
                tmp = new auto(l.Double + r);
                break;

            case 2:
                tmp = new auto(l.String + r);
                break;
            }
            return(tmp);
        }
Exemple #5
0
        // addition overload
        public static auto operator +(auto l, auto r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                tmp = l + (int)r;
                break;

            case 1:
                tmp = l + (double)r;
                break;

            case 2:
                tmp = l + (string)r;
                break;
            }
            return(tmp);
        }
Exemple #6
0
        public static auto operator -(auto l, string r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                int.TryParse(r, out int num);
                tmp = new auto(l.Int - num);
                break;

            case 1:
                double.TryParse(r, out double num1);
                tmp = new auto(l.Double - num1);
                break;

            case 2:
                Console.WriteLine("Operaotor '-' can not be applied to operands of 'string' and 'string'");
                throw new FormatException();
            }
            return(tmp);
        }
Exemple #7
0
        public static auto operator +(auto l, string r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                int.TryParse(r, out int result);
                tmp = new auto(l.Int + result);
                break;

            case 1:
                double.TryParse(r, out double result1);
                tmp = new auto(l.Double + result1);
                break;

            case 2:
                tmp = new auto(l.String + r);
                break;
            }
            return(tmp);
        }
Exemple #8
0
        // operator /
        public static auto operator /(auto l, auto r)
        {
            auto tmp = null;

            switch (l.Current)
            {
            case 0:
                tmp = l / (int)r;
                break;

            case 1:
                tmp = l / (double)r;
                break;

            case 2:
                if (r.Current == 2)
                {
                    string tmpStr = null;
                    for (int i = 0; i < l.String.Length; i++)
                    {
                        if (!(r.String.Contains(l.String[i])))
                        {
                            tmpStr += l.String[i];
                        }
                    }
                    tmp = new auto(tmpStr);
                    break;
                }
                else
                {
                    Console.WriteLine("Operaotor '/' can not be applied to operands of 'string' and 'some type'");
                    throw new FormatException();
                }
            }
            return(tmp);
        }