Sponsored Ad

Wednesday, May 5, 2010

How to pass and return arrays in methods using C#

 

This sample program will help you to pass arrays and returns arrays from a function in C#. use the below program to develop complex functions to return and accept values.

Output:

How to pass and return arrays in methods using C#

source Code:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] intArray = {  1 ,  2, 3 , 4, 5 };
            Program obj = new Program();
            int[] ResultArray = obj.PassArray(intArray);

            foreach (int ArrayItem in ResultArray)
            {
                Console.Write(ArrayItem + " ");
            }
            Console.ReadLine();

        }

        private int[] PassArray(int[] tempArray)
        {
            return tempArray;
        }
    }
}

Tuesday, May 4, 2010

How to Get Selected Date of Calendar using C#

 

This is small demonstration of a C# program to get selected date of a calendar using C#.

Calendar expose a method to get the selected date. there is other more methods, you can go though them one by one.

cldTest.SelectedDate.ToShortDateString()

 

How to Get Selected Date of Calendar using C#

 

Program Code:

 

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void cldTest_SelectionChanged(object sender, EventArgs e)
    {
        Response.Write("Your Date Selection is: " + cldTest.SelectedDate.ToShortDateString() + "<br>");       

    }
</script>

<html>
<head>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Calendar ID="cldTest" runat="server" OnSelectionChanged="cldTest_SelectionChanged"></asp:Calendar>
        </div>
    </form>
</body>
</html>

Monday, May 3, 2010

Number and Currency formatting in C#

 

The formats are given below along with example, please let me know if you face any problem.

 

Output:

Number and Currency formatting in C#

 

Source code:

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

namespace MyFirstConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int intResults = 1234567890;
            double dblResults = 12345678.90;

            Console.WriteLine("Currency format {0}: {1:C}", "{C}", intResults);

            Console.WriteLine("Decimal format {0}: {1:D}", "{D}", intResults);

            Console.WriteLine("Decimal format {0}: {1:D12}", "{D12}", intResults);

            Console.WriteLine("Exponential format {0}: {1:E}", "{E}", intResults);

            Console.WriteLine("fixed format {0}: {1:F}", "{F}", intResults);

            Console.WriteLine("fixed format {0}: {1:F5}", "{F5}", intResults);

            Console.WriteLine("number format {0}: {1:N}", "{N}", dblResults);

            Console.WriteLine("number format {0}: {1:N1}", "{N1}", dblResults);

            Console.WriteLine("hexadecimal format {0}: {1:X}", "{X}", intResults);

            Console.WriteLine(" format {0}: {1:0.000}", "{0.000}", intResults);

            Console.WriteLine(" format {0}: {1:0.##}", "{0.##}", intResults);

            Console.WriteLine("percent format {0}: {1:0%}", "{0%}", intResults);

            Console.ReadLine();
        }

    }
}

Sponsored Ad

Development Updates