working on it ...

Filters

Explore Public Snippets

Sort by

Found 17k snippets

    public by marceloviana modified Dec 19, 2016  152  0  3  0

    Formatar double para ,00

    //Converte double 
    
    double valor = double.Parse("100".ToString());
    
    string.Format("{0:n2}", decimal.Parse(valor.ToString())

    public by marceloviana modified Dec 5, 2016  121  3  3  1

    Csharp ler Json e percorrer

    var url = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    var sysnClient = new WebClient();
    string content = sysnClient.DownloadString(url);
    
                
    List<divida> lista_dados = new JavaScriptSerializer().Deserialize<List<cliente>>(content);
    
    string nomecompleto = "";
    
    foreach (divida registro in lista_dados) {
      nome_completo = registro.nome_completo;
    }
    
    txt_nomecompleto.Text = nomecompleto;

    public by Geometry modified Sep 25, 2016  108  0  3  0

    Sum: Matrix sum.

    Matrix sum. A matrix whose sum will be calculated. The dimension in which the sum will be calculated. A location where the result of this operation will be stored, avoiding unnecessary memory allocations.
    /// <summary>
            ///   Matrix sum.
            /// </summary>
            ///
            /// <param name="matrix">A matrix whose sum will be calculated.</param>
            /// <param name="dimension">The dimension in which the sum will be
            ///   calculated.</param>
            /// <param name="result">A location where the result of this operation will be stored,
            ///   avoiding unnecessary memory allocations.</param>
            ///
    #if NET45
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
    #endif
            public static decimal[] Sum(this decimal[,] matrix, int dimension, decimal[] result)
            {
                if (matrix == null) 
                    throw new ArgumentNullException("matrix");
    
                int rows = matrix.GetLength(0);
                int cols = matrix.GetLength(1);
    
                if (dimension == 0)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        decimal s = 0;
                        for (int i = 0; i < rows; i++)
                            s = (decimal)(s + (decimal)matrix[i, j]);
                        result[j] = s;
                    }
                }
                else if (dimension == 1)
                {
                    for (int j = 0; j < rows; j++)
                    {
                        decimal s = 0;
                        for (int i = 0; i < cols; i++)
                            s = (decimal)(s + (decimal)matrix[j, i]);
                        result[j] = s;
                    }
                }
                else
                {
                    throw new ArgumentException("Invalid dimension", "dimension");
                }
    
                return result;
            }

    public by Geometry modified Sep 25, 2016  112  1  3  0

    Random: Creates a matrix with uniformly distributed random data.

    Creates a matrix with uniformly distributed random data.
    /// <summary>
    ///   Creates a matrix with uniformly distributed random data.
    /// </summary>
    /// 
    public static decimal[,] Random(int size, decimal min, decimal max, bool symmetric = false, decimal[,] result = null)
    {
        if (result == null)
            result = new decimal[size, size];
    
        var random = Accord.Math.Random.Generator.Random;
    
        if (symmetric)
        {
            for (int i = 0; i < size; i++)
                for (int j = i; j < size; j++)
                    result[i, j] = result[j, i] = (decimal)random.NextDouble() * (max - min) + min;
        }
        else
        {
            for (int i = 0; i < size; i++)
                for (int j = i; j < size; j++)
                    result[i, j] = (decimal)random.NextDouble() * (max - min) + min;
        }
        return result;
    }

    public by Geometry modified Aug 6, 2016  138  1  5  0

    SetUnmanagedMemory: Fill memory region with specified value.

    Fill memory region with specified value. Destination pointer. Filler byte's value. Memory block's length to fill. Return's value of - pointer to destination.
    /// <summary>
    /// Fill memory region with specified value.
    /// </summary>
    /// 
    /// <param name="dst">Destination pointer.</param>
    /// <param name="filler">Filler byte's value.</param>
    /// <param name="count">Memory block's length to fill.</param>
    /// 
    /// <returns>Return's value of <paramref name="dst"/> - pointer to destination.</returns>
    /// 
    public static unsafe byte* SetUnmanagedMemory(byte* dst, int filler, int count)
    {
        return memset(dst, filler, count);
    }

    public by Geometry modified Aug 6, 2016  122  0  5  0

    SetUnmanagedMemory: Fill memory region with specified value.

    Fill memory region with specified value. Destination pointer. Filler byte's value. Memory block's length to fill. Return's value of - pointer to destination.
    /// <summary>
    /// Fill memory region with specified value.
    /// </summary>
    /// 
    /// <param name="dst">Destination pointer.</param>
    /// <param name="filler">Filler byte's value.</param>
    /// <param name="count">Memory block's length to fill.</param>
    /// 
    /// <returns>Return's value of <paramref name="dst"/> - pointer to destination.</returns>
    /// 
    public static IntPtr SetUnmanagedMemory(IntPtr dst, int filler, int count)
    {
        unsafe
        {
            SetUnmanagedMemory((byte*)dst.ToPointer(), filler, count);
        }
        return dst;
    }

    public by Geometry modified Aug 6, 2016  135  0  5  0

    CopyUnmanagedMemory: Copy block of unmanaged memory.

    Copy block of unmanaged memory. Destination pointer. Source pointer. Memory block's length to copy. Return's value of - pointer to destination. This function is required because of the fact that .NET does not provide any way to copy unmanaged blocks, but provides only methods to copy from unmanaged memory to managed memory and vi
    /// <summary>
    /// Copy block of unmanaged memory.
    /// </summary>
    /// 
    /// <param name="dst">Destination pointer.</param>
    /// <param name="src">Source pointer.</param>
    /// <param name="count">Memory block's length to copy.</param>
    /// 
    /// <returns>Return's value of <paramref name="dst"/> - pointer to destination.</returns>
    /// 
    /// <remarks><para>This function is required because of the fact that .NET does
    /// not provide any way to copy unmanaged blocks, but provides only methods to
    /// copy from unmanaged memory to managed memory and vise versa.</para></remarks>
    /// 
    public static unsafe byte* CopyUnmanagedMemory(byte* dst, byte* src, int count)
    {
        return memcpy(dst, src, count);
    }

    public by Geometry modified Aug 6, 2016  127  0  5  0

    CopyUnmanagedMemory: Copy block of unmanaged memory.

    Copy block of unmanaged memory. Destination pointer. Source pointer. Memory block's length to copy. Return's value of - pointer to destination. This function is required because of the fact that .NET does not provide any way to copy unmanaged blocks, but provides only methods to copy from unmanaged memory to managed memory and vi
    /// <summary>
    /// Copy block of unmanaged memory.
    /// </summary>
    /// 
    /// <param name="dst">Destination pointer.</param>
    /// <param name="src">Source pointer.</param>
    /// <param name="count">Memory block's length to copy.</param>
    /// 
    /// <returns>Return's value of <paramref name="dst"/> - pointer to destination.</returns>
    /// 
    /// <remarks><para>This function is required because of the fact that .NET does
    /// not provide any way to copy unmanaged blocks, but provides only methods to
    /// copy from unmanaged memory to managed memory and vise versa.</para></remarks>
    ///
    public static IntPtr CopyUnmanagedMemory(IntPtr dst, IntPtr src, int count)
    {
        unsafe
        {
            CopyUnmanagedMemory((byte*)dst.ToPointer(), (byte*)src.ToPointer(), count);
        }
        return dst;
    }

    public by Geometry modified Aug 6, 2016  150  0  5  0

    Evaluate: Evaluates specified expression.

    Evaluates specified expression. Expression written in postfix polish notation. Variables for the expression. Evaluated value of the expression. Unsupported function is used in the expression. Incorrect postfix polish expression.
    /// <summary>
    /// Evaluates specified expression.
    /// </summary>
    ///
    /// <param name="expression">Expression written in postfix polish notation.</param>
    /// <param name="variables">Variables for the expression.</param>
    /// 
    /// <returns>Evaluated value of the expression.</returns>
    /// 
    /// <exception cref="ArgumentException">Unsupported function is used in the expression.</exception>
    /// <exception cref="ArgumentException">Incorrect postfix polish expression.</exception>
    ///
    public static double Evaluate(string expression, double[] variables)
    {
        // split expression to separate tokens, which represent functions ans variables
        string[] tokens = expression.Trim().Split(' ');
        // arguments stack
        Stack<double> arguments = new Stack<double>();
    
        // walk through all tokens
        foreach (string token in tokens)
        {
            // check for token type
            if (char.IsDigit(token[0]))
            {
                // the token in numeric argument
                arguments.Push(double.Parse(token));
            }
            else if (token[0] == '$')
            {
                // the token is variable
                arguments.Push(variables[int.Parse(token.Substring(1))]);
            }
            else
            {
                // each function has at least one argument, so let's get the top one
                // argument from stack
                double v = (double)arguments.Pop();
    
                // check for function
                switch (token)
                {
                    case "+":			// addition
                        arguments.Push((double)arguments.Pop() + v);
                        break;
    
                    case "-":			// subtraction
                        arguments.Push((double)arguments.Pop() - v);
                        break;
    
                    case "*":			// multiplication
                        arguments.Push((double)arguments.Pop() * v);
                        break;
    
                    case "/":			// division
                        arguments.Push((double)arguments.Pop() / v);
                        break;
    
                    case "sin":			// sine
                        arguments.Push(System.Math.Sin(v));
                        break;
    
                    case "cos":			// cosine
                        arguments.Push(System.Math.Cos(v));
                        break;
    
                    case "ln":			// natural logarithm
                        arguments.Push(System.Math.Log(v));
                        break;
    
                    case "exp":			// exponent
                        arguments.Push(System.Math.Exp(v));
                        break;
    
                    case "sqrt":		// square root
                        arguments.Push(System.Math.Sqrt(v));
                        break;
    
                    default:
                        // throw exception informing about undefined function
                        throw new ArgumentException("Unsupported function: " + token);
                }
            }
        }
    
        // check stack size
        if (arguments.Count != 1)
        {
            throw new ArgumentException("Incorrect expression.");
        }
    
        // return the only value from stack
        return (double)arguments.Pop();
    }

    public by Geometry modified Aug 6, 2016  130  0  5  0

    FromDense: Creates a sparse vector from a dense array.

    Creates a sparse vector from a dense array.
    /// <summary>
    ///   Creates a sparse vector from a dense array.
    /// </summary>
    /// 
    public static Sparse<T> FromDense<T>(T[] dense)
    {
        int[] idx = new int[dense.Length];
        for (int i = 0; i < idx.Length; i++)
            idx[i] = i;
        return new Sparse<T>(idx, dense);
    }
    • Public Snippets
    • Channels Snippets