Saturday, May 23, 2015

All Coutries From System.Globalization Namespace List All Countries In DropDownList get

ASPX Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div style="margin: 150px;">
            <h2>Random Country List</h2>
            <asp:DropDownList ID="ddlCountries" runat="server">
                <asp:ListItem Value="0">Select Country</asp:ListItem>
            </asp:DropDownList>

            <h2>Sorted Country List</h2>
            <asp:DropDownList ID="ddlSortedCountries" runat="server">
                <asp:ListItem Value="0">Select Country</asp:ListItem>
            </asp:DropDownList>
            Source: <a href=" " target="_blank">.Net Pickles</a>
        </div>
    </form>
</body>
</html>

Below is the code behind code.
 
C#.Net Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Declaring dictionary object to add coutries from the System.Globalization namespace
        Dictionary<string, string> objCountries = new Dictionary<string, string>();

        //Getting coutries from CultureInfo class and adding it to objCountries
        foreach (CultureInfo objCultureInfo inCultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            RegionInfo objRegionInfo = new RegionInfo(objCultureInfo.Name);
            if (!objCountries.ContainsKey(objRegionInfo.GeoId.ToString()))
            {
                objCountries.Add(objRegionInfo.GeoId.ToString(), objRegionInfo.EnglishName);
            }
        }

        //Looping dictionary object and binding it to drop down
        foreach (var key in objCountries.Keys)
        {
            ddlCountries.Items.Add(new ListItem(objCountries[key], objCountries[key]));
        }

        //Sorting the dictionary object based on value
        List<KeyValuePair<string, string>> mySortedList = objCountries.ToList();
        mySortedList.Sort(
            delegate(KeyValuePair<string, string> firstPair,
            KeyValuePair<string, string> nextPair)
            {
                return firstPair.Value.CompareTo(nextPair.Value);
            }
        );

        //Binding sorted dictionary object to dropdownlist
        foreach (KeyValuePair<string, string> objKeyValuePair in mySortedList)
        {
            ddlSortedCountries.Items.Add(new ListItem(objKeyValuePair.Value, objKeyValuePair.Key));
        }
    }
}


Sunday, December 7, 2014

fibonacci series in asp.net, ArmStrong Number, PalindromeNumberOrNot





ArmStrong Number


namespace DotNetMirror
{
    class ArmStrongNumber
    {
        public static void Main()
        {
            Console.WriteLine("********** ArmStrong Number Check Example ********");
            Console.WriteLine("Enter Number to Want to check");
            int numberToCheck = int.Parse(Console.ReadLine());
            int lenthOfNumber = numberToCheck.ToString().Length;
            double reminder = 0;
            double sum = 0;
            int tempNo = numberToCheck;
            while (tempNo > 0)
            {
                reminder = tempNo % 10;
                sum = sum + Math.Pow(reminder, lenthOfNumber);
                tempNo = tempNo / 10;
            }
            if (sum == numberToCheck)
            {
                Console.WriteLine("The given Number {0} is a Armstrong Number", numberToCheck);
            }
            else
            {
                Console.WriteLine("The given Number {0} is NOT a Armstrong Number", numberToCheck);
            }
            Console.ReadLine();
        }
    }
}
Fibonaci
using System;

namespace Fibonaccinumber
{
    class Program
    {
        static void Main(string[] args)
        {
           
            int a=0;     // assigning initaial value for first varible
            int b=1;     // assigning initaial value for second  varible
            int c=1;     // assigning initaial value for third varible

            Console.WriteLine(a);
            Console.WriteLine(b);
            while (true)
            {

                c = a + b; 
                if (c >= 200)
                {
                    break;
                }
                Console.WriteLine(c);
                a = b;
                b = c;

            }
            Console.Read();  // to keep windows screen after running

        }
    }
}

Palindrome
class PalindromeNumberOrNot
{
    public static void Main()
    {
        Console.WriteLine("********** Palindrome Number Check Example ********");
        Console.WriteLine("Enter Number to Want to check");
        int numberToCheck = int.Parse(Console.ReadLine());
        int lenthOfNumber = numberToCheck.ToString().Length;
        double reminder = 0;
        double sum = 0;
        int tempNo = numberToCheck;
        while (tempNo > 0)
        {
            reminder = tempNo % 10;
            sum = sum * 10 + reminder;
            tempNo = tempNo / 10;

        }
        if (sum == numberToCheck)
        {
            Console.WriteLine("The given Number {0} is a Palindrome Number", numberToCheck);
        }
        else
        {
            Console.WriteLine("The given Number {0} is NOT a Palindrome Number", numberToCheck);
        }
    }
}