Chote magar mote question in c#





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Collections;

namespace Chote_Chote_Magar_Mote_Question
{
    public partial class Learning : Form
    {
        int value = -123;//for example like this is value that convert
        
        string convtval = string.Empty; 
        string number = "0123456789";
        bool chkval = false;
        int v = 0;
        int start, end;
        public Learning()
        {
            InitializeComponent();
        }

        private void btnconvIntToString_Click(object sender, EventArgs e)
        {

            if (value < 0)//here check value is nigate or positive
                chkval = true;

            value = Math.Abs(value); //with the help of this method find absolute value like as 123

            while (value > 0) //loop execute when value greater than zero
            {
                v = value % 10; // find first one digit like 1
                value = value/10; 
                foreach (char letter in number)
                {
                    if (v == letter - 48)
                    {
                        convtval += letter.ToString();
                        break;
                    }
                }
                               
            }
            string ns = new string(convtval.Reverse().ToArray());

            if (chkval == true)
                ns = "-" + ns;
            MessageBox.Show(ns);

        }

        private void btnregularexpresson_Click(object sender, EventArgs e)
        {
            double a = 4.0;
            double b = 12.0;
            double c = a + b;
           
            string sPattern = "^[0-9][0-9][0-9]+\\.?[0-9][0-9][0-9][0-9]$";
            string input = "123.0000";
            if (Regex.IsMatch(input, sPattern))
            {
                MessageBox.Show("(match for '{0}' found)", sPattern);
            }
            else
            {
                System.Console.WriteLine();
            }
        }

      
        private void btbwithoutDoevent_Click(object sender, EventArgs e)
        {
            start = Convert.ToInt32( txtsartval.Text);
            end = Convert.ToInt32(txtendval.Text);
            lblStatus.Text = "";
            pgbdoeventprocess.Maximum = end;
            pgbdoeventprocess.Minimum = start;
            for (int nValue = start; nValue <= end; nValue++)
            {
                lblStatus.Text = "Processing item: " + Convert.ToString(nValue);
                pgbdoeventprocess.Value = nValue;
            }
        }

        private void btnwithDoEvent_Click(object sender, EventArgs e)
        {
            start = Convert.ToInt32(txtsartval.Text);
            end = Convert.ToInt32(txtendval.Text);

            pgbdoeventprocess.Maximum = end;
            pgbdoeventprocess.Minimum = start;
            lblStatus.Text = "";
            for (int nValue = start; nValue <= end; nValue++)
            {
                lblStatus.Text = "Processing item: " + Convert.ToString(nValue);
                pgbdoeventprocess.Value = nValue;

                Application.DoEvents();
            }
        }

        private void btnconvStrngtoInt_Click(object sender, EventArgs e)
        {
            string svalue = "123";

            int value = 0;

            foreach (char c in svalue)
            {
                value=value*10+(c-'0');

            }
            MessageBox.Show(value.ToString());
        }

        private void btnhashtable_Click(object sender, EventArgs e)
        {
            Hashtable hastable = new Hashtable();

            hastable.Add("One",1);
            hastable.Add("Two", 2);
            hastable.Add("Three", "No Value");
            hastable.Add("Four", 4);
            hastable.Add("Five", 5);
            foreach (DictionaryEntry child in hastable)
            {
                listhashtableuse.Items.Add("Key="+child.Key+", Value="+child.Value);
            }

        }

        private void btndictionaryuse_Click(object sender, EventArgs e)
        {
            Dictionary<string, int> dictionary = new Dictionary<string, int>();

            dictionary.Add("cat", 2);
            dictionary.Add("dog", 1);
            dictionary.Add("llama", 0);
            dictionary.Add("iguana", -1);

            foreach (KeyValuePair<string, int> pair in dictionary)
            {
                listhashtableuse.Items.Add("Key="+ pair.Key+", Value="+ pair.Value);
            }
            // Use var keyword to enumerate dictionary.
            foreach (var pair in dictionary)
            {
                Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
            }
            MessageBox.Show("{{my nae}}");
        }

        private void btnConvfloatToBinary_Click(object sender, EventArgs e)
        {
            double fvalue = 322.23, afterpointvalue = 0.0;
            int Beforepointpvalue = 0; int p;
            int Binaryvalue = 0;
            Beforepointpvalue = (int)fvalue;

            afterpointvalue =fvalue- Beforepointpvalue;

            while (Beforepointpvalue > 0)
            {
                p = Beforepointpvalue % 2;
                Binaryvalue = Binaryvalue * 10 + p;
                Beforepointpvalue = Beforepointpvalue / 2;
            }

            // after point value binary number
            int i=0,temp;
            double Binaryvalueafterpoint = 0.0;
            
            double factor = 0.1;
            while (i < 5)
            {
                afterpointvalue = afterpointvalue * 2;
                temp = (int)afterpointvalue;

                Binaryvalueafterpoint = Binaryvalueafterpoint + factor * temp;

                if (temp == 1)
                    afterpointvalue = afterpointvalue - temp;

                factor = factor / 10;
                i++;
            }

            Binaryvalueafterpoint = Binaryvalue + Binaryvalueafterpoint;

            MessageBox.Show(Binaryvalueafterpoint.ToString());
                  
        }
        
    }
}

Comments