Pages

Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Wednesday, July 11, 2012

Bubble Sort


Simplest sorting algorithm which is frequently used is Bubble sort. The bubble sort works on a fairly simple algorithm where items are sort by iterating down an array and sorted with the first element to the last, here we compare each set of value and then switch their positions if required. This same method is continue until the array is sorted. The maximum iteration can occur in a case where the array is in reverse order, where the first value needs to be swapped with the last value. In this case the maximum iteration required to sort the complete array will be same as the array length.
Here is a Simple demonstration of the code in C# where the for loop is used to perform the iteration and a temporary array is used to store the sorted values. 

The algorithm works on the principle of swapping the value by comparing them, here is a pictorail demonstration of the task. This will give a clear idea for the whole process.


 Here is the Implementation using the C# code

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

            int i = 0, j = 0, t = 0;
            int[] unSortedArray = new int[20];
            for (i = 0; i < 10; i++)
            {
                Console.WriteLine("Enter Value p[{0}]:", i);
                unSortedArray[i] = int.Parse(Console.ReadLine());
            }
            // Sorting Algorithm  Starts here - Bubble Sort
            for (i = 0; i < 10; i++)
            {
                for (j = i + 1; j < 10; j++)
                {
                    if (unSortedArray[i] > unSortedArray[j])
                    {                       
                        t = unSortedArray[i];
                        unSortedArray[i] = unSortedArray[j];
                        unSortedArray[j] = t;
                    }
                }
            }
            Console.WriteLine("\n The sorted array:\n");

            for (i = 0; i < 10; i++)
            {
                Console.WriteLine("Sorted Array[{0}]={1}", i, unSortedArray[i]);
            }

            Console.WriteLine("n Please Press a Key to Exit");
            Console.ReadLine();
        }
    }
}


Hope this piece of code is very useful for you in creating your sort functionality. Please provide the valuable comment by which I can improve the performance and code structure.


Thanks
Anil Kumar Pandey
Microsoft MVP, Microsoft MCC,DNS MVM

Friday, March 16, 2012

Visual Studio 2011 Beta


Microsoft® VisualStudio™ 11 Beta

Visual Studio 11 Beta Is Here


Download the Beta Now


Sign Up Now


Download Visual Studio 11 Beta today!

Get Visual Studio 11 Beta today and start preparing for the next generation of
development. You can’t predict the future, but you can get there first:

• New HTML and CSS editors extend Visual Studio’s rich editing capabilities to
make HTML 5 and CSS 3 development more productive, as well as enrich
traditional HTML development.

• Visual Studio 11 gives you the tools required to build and deploy Windows Azure
applications, including project templates, a seamless debugging experience, and
easy publishing.

• New designers make building Windows 8 Metro and traditional Windows desktop
applications easier and faster than ever.

• Flexible agile planning tools (like capacity planning, task boards, and product
backlog) allow teams to adopt incremental development techniques and agile
methodologies, like SCRUM, at their own pace.


DOWNLOAD BETA TODAY


Be the first to know!

Get the latest information about downloads, news, and tips for the
next release of Visual Studio delivered directly to your inbox.


SIGN UP TODAY



Sign Up Now



Monday, November 8, 2010

New Features of Visual c# 4.0

Hello All,
One of my MVP friend has written a very beautiful articles on the latest features of the Visual C# 4.0. I would like to share with you, Please follow the below link and read this article. I hope you will like that.


Hope you will like this.


Thanks & Regards,
Anil Kumar Pandey
MVP Visual C#

Wednesday, December 9, 2009

Escape Sequences


While Coding we use many special characters, and we have seen some characters which start with a backslash ("\"). All the characters which starts from backslash ("\") is known as the escape sequence. There are several escape sequence are used in the c# here are the list of that. you can use them according to the use..

\a Bell (alert)
\b Backspace
\f Formfeed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\? Literal question mark
\ooo ASCII character in octal notation
\xhh ASCII character in hexadecimal notation
\xhhhh Unicode character in hexadecimal notation if this escape sequence is used in a wide-character constant or a Unicode string literal.


Hope the information was useful.. Happy coding!!!!


Thanks
Anil Kumar Pandey
System Architect, MVP
Mumbai, Maharshtra

Wednesday, August 19, 2009

Sending SMS from .Net application

hi,

.Net has the support for the mobile device. Using the Application we can send SMS to the mobile device, for this i am using the 2 web service in the application that are com.webservicex.www & net.webservicex.www. We simply need to create an interface from which we can supply the mobile no and the message. Using this service not only we can send message to India but we also can send the message to international numbers. You just need to add the Web reference in ypur application for this 2 web services.

please refer this code for .CS page.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace SmsTest
{
///
/// Summary description for WebForm1.
///

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Send;
protected System.Web.UI.WebControls.TextBox txtMobileNo;
protected System.Web.UI.WebControls.TextBox txtEmailId;
protected System.Web.UI.WebControls.TextBox txtCountryCode;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.RadioButtonList rdoType;
protected System.Web.UI.WebControls.TextBox txtMessage;

private void Page_Load(object sender, System.EventArgs e)
{
txtCountryCode.
Enabled = false;
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent
();
base.OnInit(e);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.Send.Click += new System.EventHandler(this.Send_Click);
this.rdoType.SelectedIndexChanged += new System.EventHandler(this.rdoType_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Send_Click(object sender, System.EventArgs e)
{
if (txtEmailId.Text.Trim() == "")
{
lblMessage.
Visible = true;
lblMessage.
Text = "Please Enter Email ID";
txtEmailId.
Focus();
return
;
}
else if (txtMobileNo.Text.Trim() == "")
{
lblMessage.
Visible = true;
lblMessage.
Text = "Please Enter Mobile No";
txtMobileNo.
Focus();
return
;
}
else if (txtMessage.Text.Trim() == "")
{
lblMessage.
Visible = true;
lblMessage.
Text = "Please Enter Message";
txtMessage.
Focus();
return
;
}
else
{
try
{
SmsTest.
net.webservicex.www.SendSMS smsIndia = new SmsTest.net.webservicex.www.SendSMS();
SmsTest.
com.webservicex.www.SendSMSWorld smsWorld = new SmsTest.com.webservicex.www.SendSMSWorld();
if (rdoType.SelectedValue == "1")
smsIndia.
SendSMSToIndia(txtMobileNo.Text.Trim(), txtEmailId.Text.Trim(), txtMessage.Text);
else
smsWorld.
sendSMS(txtEmailId.Text.Trim(), txtCountryCode.Text.Trim(), txtMobileNo.Text.Trim(), txtMessage.Text);
lblMessage.
Visible = true;
lblMessage.
Text = "Message Send Succesfully";
}
catch (Exception ex)
{
lblMessage.
Visible = true;
lblMessage.
Text = "Error in Sending message" + ex.ToString();
}
}
}

private void rdoType_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(rdoType.SelectedValue =="1")
txtCountryCode.
Enabled = false;
else
txtCountryCode.
Enabled = false;

}

protected void Clear_Click(object sender, EventArgs e)
{
txtEmailId.
Text = "";
txtCountryCode.
Text = "";
txtMobileNo.
Text = "";
txtMessage.
Text = "";
lblMessage.
Visible = false;
txtEmailId.
Focus();
}
}
}


And here is the .aspx page code.

<%@ Page Language="c#" CodeBehind="SendSms.aspx.cs" AutoEventWireup="false" Inherits="SmsTest.WebForm1" %>

<html>
<head>
<title>Sending Text Messages with .NETtitle>
head>
<body>
<table width="100%" border="1px">
<tr>
<td align="center">
<h2>
Send SMS
h2>
td>
tr>
<tr>
<td align="center">
<asp:Label ID="lblMessage" runat="server" ForeColor="#009900" Visible="False">asp:Label>
td>
tr>
table>
<form method="post" runat="server" id="Form1">
<table width="100%" border="1px">
<tr>
<td colspan="2" height="22">
&nbsp;
<asp:RadioButtonList ID="rdoType" runat="server" AutoPostBack="True" RepeatDirection="Horizontal"
Width
="304px">
<asp:ListItem Value="1" Selected="True">SMS to Indiaasp:ListItem>
<asp:ListItem Value="2">SMS to worldasp:ListItem>
asp:RadioButtonList>
td>
tr>
<tr>
<td>
Email Id
td>
<td>
<asp:TextBox ID="txtEmailId" runat="server">asp:TextBox>( ex :&nbsp;test@test.com
)
td>
tr>
<tr>
<td>
Country Code
td>
<td>
<asp:TextBox ID="txtCountryCode" runat="server" Text="">asp:TextBox>&nbsp;(ex
: 91 for&nbsp;India
td>
tr>
<tr>
<td>
Mobile
/cell Number
td>
<td>
<asp:TextBox ID="txtMobileNo" runat="server" Text="">asp:TextBox>&nbsp;( ex :&nbsp;984xxxxxxxx&nbsp;)
td>
tr>
<tr>
<td>
Message
td>
<td>
<asp:TextBox ID="txtMessage" runat="server" Rows="4" TextMode="MultiLine">asp:TextBox>
td>
tr>
<tr>
<td>
td>
<td>
<asp:Button ID="Send" runat="server" Text="Send">asp:Button>
<asp:Button ID="Clear" runat="server" Text="Clear" OnClick="Clear_Click">asp:Button>
td>
tr>
table>
form>
body>
html>


I have taken the idea from one of the leading sites. You can refer the main article here. Source.

I hope now you can easily send SMS using this application.

happy coding!!!!!!!!

Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra

Kontera