C Sharp Shorten Class

By wade2462 on Jun 24, 2010

It Shortens everyday functions that are used with the console. Documentation in code using XML.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shortener
{
    /// <summary>
    /// SShort is a class to shorten common methods and processes dealing with Strings
    /// </summary>
    class SShort
    {
        /// <summary>
        /// shorten the System.Console.WriteLine() and System.Console.Write()
        /// Methods
        /// </summary>
        /// <param name="Choice"> Chose wheter you want 0.Write() or 1.WriteLine()</param>
        /// <param name="ToWrite"> String to Write</param>
        public static void write(int Choice, string ToWrite)
        {
            if (Choice == 0)
            {
                System.Console.Write(ToWrite);
            }
            else if (Choice == 1)
            {
                System.Console.WriteLine(ToWrite);
            }
        }
        /// <summary>
        /// Easy way to read a string of characters from the console into a string
        /// </summary>
        /// <param name="Empty">ref value to store input</param>
        public static void GetString(ref string Empty)
        {
            Empty = System.Console.ReadLine();
        }

    }
    /// <summary>
    /// SShort is a class to shorten common methods and processes dealing with Numbers
    /// </summary>
    class NShort
    {
        /// <summary>
        /// Easy way to read a string of numbers from the console into an int
        /// </summary>
        /// <param name="Empty">ref value to store input</param>
        public static void GetInt(ref int Empty)
        {
            Empty = int.Parse(Console.ReadLine());
        }

        /// <summary>
        /// Easy way to read a string of numbers from the console into a double
        /// </summary>
        /// <param name="Empty">ref value to store input</param>
        public static void GetDouble(ref double Empty)
        {
            Empty = double.Parse(Console.ReadLine());
        }

        /// <summary>
        /// Easy Pythagorean Theorem.
        /// Supply zero for number to solve for.
        /// Returns a double to be assigned to a variable or to be used for output
        /// </summary>
        /// <param name="A">Height</param>
        /// <param name="B">Base</param>
        /// <param name="C">Hypotenuse</param>
        /// <returns></returns>
        public static double Pythagorean(double A = 0, double B = 0, double C = 0)
        {
            if (A != 0 && B != 0)
            {
                return (System.Math.Sqrt(System.Math.Pow(A, 2) + System.Math.Pow(B, 2)));
            }
            else if (A != 0 && C != 0)
            {
                return (System.Math.Sqrt(System.Math.Pow(C, 2) - System.Math.Pow(A, 2)));
            }
            else if (B != 0 && C != 0)
            {
                return (System.Math.Sqrt(System.Math.Pow(C, 2) - System.Math.Pow(B, 2)));
            }
            else
            {
                return 0;
            }
        }

    }
    /// <summary>
    /// CShort is a class to shorten common methods and procceses dealing with the console
    /// </summary>
    class CShort
    {
        /// <summary>
        /// FColor is an easy way to set the Foreground Color of the Console
        /// </summary>
        /// <param name="Color">A color that is supported such as "Red", "Dark Red" or "Cyan"</param>
        public static void FColor(string Color)
        {
            if (Color == "Red")
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }

            else if (Color == "Dark Red")
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
            }

            else if (Color == "Blue")
            {
                Console.ForegroundColor = ConsoleColor.Blue;
            }

            else if (Color == "Dark Blue")
            {
                Console.ForegroundColor = ConsoleColor.DarkBlue;
            }

            else if (Color == "Cyan")
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
            }

            else if (Color == "Dark Cyan")
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
            }

            else if (Color == "Magenta")
            {
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
            }

            else if (Color == "Yellow")
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }

            else if (Color == "Dark Yellow")
            {
                Console.ForegroundColor = ConsoleColor.DarkYellow;
            }

            else if (Color == "Green")
            {
                Console.ForegroundColor = ConsoleColor.Green;
            }

            else if (Color == "Dark Green")
            {
                Console.ForegroundColor = ConsoleColor.DarkGreen;
            }

            else if (Color == "Black")
            {
                Console.ForegroundColor = ConsoleColor.Black;
            }

            else if (Color == "Gray")
            {
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            else if (Color == "Dark Gray")
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
            }

            else if (Color == "White")
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
            }

        }

/// <summary>
/// BColor is an easy way to set the Background Color of the Console
/// </summary>
/// <param name="Color">A color that is supported such as "Red", "Dark Red" or "Cyan"</param>
       public static void BColor(string Color)
        {
            if (Color == "Red")
            {
                Console.BackgroundColor = ConsoleColor.Red;
            }

            else if (Color == "Dark Red")
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
            }

            else if (Color == "Blue")
            {
                Console.BackgroundColor = ConsoleColor.Blue;
            }

            else if (Color == "Dark Blue")
            {
                Console.BackgroundColor = ConsoleColor.DarkBlue;
            }

            else if (Color == "Cyan")
            {
                Console.BackgroundColor = ConsoleColor.Cyan;
            }

            else if (Color == "Dark Cyan")
            {
                Console.BackgroundColor = ConsoleColor.DarkCyan;
            }

            else if (Color == "Magenta")
            {
                Console.BackgroundColor = ConsoleColor.DarkMagenta;
            }

            else if (Color == "Yellow")
            {
                Console.BackgroundColor = ConsoleColor.Yellow;
            }

            else if (Color == "Dark Yellow")
            {
                Console.BackgroundColor = ConsoleColor.DarkYellow;
            }

            else if (Color == "Green")
            {
                Console.BackgroundColor = ConsoleColor.Green;
            }

            else if (Color == "Dark Green")
            {
                Console.BackgroundColor = ConsoleColor.DarkGreen;
            }

            else if (Color == "Black")
            {
                Console.BackgroundColor = ConsoleColor.Black;
            }

            else if (Color == "Gray")
            {
                Console.BackgroundColor = ConsoleColor.Gray;
            }

            else if (Color == "Dark Gray")
            {
                Console.BackgroundColor = ConsoleColor.DarkGray;
            }

            else if (Color == "White")
            {
                Console.BackgroundColor = ConsoleColor.White;
            }

            else
            {
            }

        }

/// <summary>
/// An Easy And Short Way To Set The Title Of The Console Window
/// </summary>
/// <param name="Title">Title of Window</param>
       public static void Title(string Title)
       {
           Console.Title = Title;
       }
    }

}

Comments

Sign in to comment.
abatishchev   -  Apr 25, 2011

Use switch (color) instead of nested if-elseif

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.