Search This Blog

Saturday, 20 February 2016

Full Example

While Loop Example Program:

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

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the number to generate");
            int UserTarget = int.Parse(Console.ReadLine());
            int Start = 0;
            while (Start <= UserTarget)
            {
                Console.WriteLine(Start);
                Start += 2; //Start = Start + 2;
            }
        }
    }
}


2.do While loop Example Program:

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

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            String UserChoice = "";
            do
            {
                Console.WriteLine("Enter the number to generate");
                int UserTarget = Convert.ToInt32(Console.ReadLine());
                int Start = 0;
                while (Start <= UserTarget)
                {
                    Console.WriteLine(Start);
                    Start += 2; //Start = Start + 2;
                }
                Console.WriteLine("Do you want to continue-'Yes' or 'No'");
                UserChoice = (Console.ReadLine().ToUpper());
                if (UserChoice != "YES" && UserChoice != "NO")
                {
                    Console.WriteLine("Invalid Operation!");
                    Console.WriteLine("Enter 'Yes' or 'No'");
                }
            } while (UserChoice == "YES");
            Console.WriteLine("Thank You!");
        }
    }
}


3.Example while loop program with using array:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Numbers = new int[3];

            Numbers[0] = 101;
            Numbers[1] = 102;
            Numbers[2] = 102;
           
            int i=0;
            while(i<Numbers.Length)
            {
                Console.WriteLine(Numbers[i]);
                i++;
            }
        }
    }
}

Operator overloading Example program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication10
{
    class Box
    {
        private double length;
        private double breadth;
        private double height;

        public double getLength()
        {
            return length * breadth * height;
        }
        public void setLength(double len)
        {
            length = len;
        }
        public void setBreadth(double bre)
        {
            breadth = bre;
        }
        public void setHeight(double hei)
        {
            height = hei;
        }
        public static Box operator +(Box b, Box c)
        {
            Box box = new Box();
            box.length = b.length + c.length;
            box.breadth = b.breadth + c.breadth;
            box.height = b.height + c.height;
            return box;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Box Box1 = new Box();
            Box Box2 = new Box();
            Box Box3 = new Box();
            double volume = 0.0;

            Box1.setBreadth(6.0);
            Box1.setHeight(7.0);
            Box1.setLength(8.0);

            Box2.setBreadth(12.0);
            Box2.setHeight(13.0);
            Box3.setLength(14.0);

            volume = Box1.getLength();
            Console.WriteLine("the box1 value is:{0}", volume);
            volume = Box2.getLength();
            Console.WriteLine("the box2 value is:{0}", volume);

            Box3 = Box1 + Box2;

            volume = Box3.getLength();
            Console.WriteLine("the box3 value is:{0}", volume);
            Console.ReadKey();
          
        }
    }
}

Split string example program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication10
{
   
    class Program
    {
        static void Main(string[] args)
        {
            string siva = "abc,def,ghi,j";
            string[] buff = siva.Split(',');
            //Console.WriteLine(buff.Length-1);
            for (int i = 0; i < buff.Length; i++)
            {
                Console.WriteLine(buff[i]);
            }
            //foreach (string s in buff)
            //{
            //    Console.WriteLine(s);
            //    //Console.ReadKey();
            //}



            //string str = "1111222233334444";
            //MatchCollection mc = Regex.Matches(str, @"\w{3}");
            //for (int i = 0; i < mc.Count; i++)
            //{
            //    Console.WriteLine("--" + mc[i].Value + "--");
            //    Console.ReadKey();
            //}
           
        }
    }
}


Switch on off program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication13
{
   
    class Program
    {

        static void Main(string[] args)
        {
        
            string y;
            do{
                Console.WriteLine("siva");
                    do
                    {
                       // Console.WriteLine("do u want 'on' or'off'");
                        y = (Console.ReadLine());
                        //if(y=="on")
                       // Console.WriteLine("the switch is already on condition");
                    } while (y == "on");

                    do
                    {
                        //Console.WriteLine("do u want to 'on' or 'off'");
                        y = (Console.ReadLine());
                        //if(y=="off")
                       // Console.WriteLine("the switch is already off condition");
                    } while (y == "off");
               
            } while (y == "on");

        }
    }
}

File retrieve and edit and update in window.
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.IO;

namespace openfile_and_savefile
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
        }

       

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Open_Click_1(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                label1.Text = openFileDialog1.FileName;
                textBox1.Text = File.ReadAllText(label1.Text);
            }
        }

        private void Save_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                File.WriteAllText(saveFileDialog1.FileName, textBox1.Text);
            }
        }
    }
}

//using tools--->

//--All windows forms:
//1.open button.
//2.save button.
//3.Textbox-->Multiline;

//--Dialogs:
//1.OpenFileDialog
//2.saveFileDialog

Simple mail sending program:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class Sending_mail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
  
    protected void Button2_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient();

        mail.From = new MailAddress("javaatmind@gmail.com");
        mail.To.Add(TextBox1.Text);
        mail.Subject = TextBox2.Text;
        mail.Body = TextBox3.Text;
        mail.IsBodyHtml = true;

        SmtpServer.Host = "smtp.gmail.com";
        SmtpServer.Port = 587;
        System.Net.NetworkCredential Networkcred = new System.Net.NetworkCredential();
        Networkcred.UserName = "javaatmind@gmail.com";
        Networkcred.Password = "vinayagasiva.";
        SmtpServer.UseDefaultCredentials = true;
        SmtpServer.Credentials = Networkcred;
        SmtpServer.EnableSsl = true;
       
  

        SmtpServer.Send(mail);
        Label5.Text = "Message send successfully";
    }
}

//note:
//https://www.google.com/settings/security/lesssecureapps
//goto to this link and to activate less secure apps turn on.

Random Number generator program:
protected void Button1_Click1(object sender, EventArgs e)
    {
        Random rad = new Random();
        Label3.Text = rad.Next(500, 600).ToString();

        var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        var stringChars = new char[5];
        Random random = new Random();

        for (int i = 0; i < stringChars.Length; i++)
        {
            stringChars[i] = chars[random.Next(chars.Length)];
        }

        var finalString = new String(stringChars);
        Console.WriteLine(finalString.ToUpper());
        //final output generate number
        Label3.Text = finalString.ToUpper();
}

Stored Procedure:
Button_click
{
con.Open();
        SqlCommand cmd = new SqlCommand("PatientReg"àstore procedure name, con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter p1 = new SqlParameter("", finalString.ToUpper());
        cmd.Parameters.Add(p1);

}

No comments:

Post a Comment