Send Email With Gmail SMTP server Setting in ASP.NET
Here i used parameterized function like i passed all the values of the mail through the parameter values
public void funSendEmail(string txtToAdd, string txtCCAdd, string txtFromAdd, string txtSubject, string txtEmailBody)
{
MailMessage message = new MailMessage();
message.To.Add(new MailAddress(txtToAdd));
message.CC.Add(new MailAddress(txtCCAdd));
message.From = new MailAddress(txtFromAdd);
string NetworkPassword = "you mail account password"; //Network password is you mail account password
message.Subject = txtSubject;
message.Body = txtEmailBody;
message.IsBodyHtml = true;
message.Priority = MailPriority.High;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential(txtFromAdd, NetworkPassword);
smtp.Port = 587; // Gmail works on this port
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.Send(message);
}
Thursday, September 30, 2010
Wednesday, September 29, 2010
Creating Checkboxes at Runtime by using Database
You can easily add checkbox items to your form dynamically by using database as follows
int X=50;
CheckBox[] L;
SqlConnection con = new SqlConnection("user id=sa;password=;database=college");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter("select * from studentdata", con);
DataSet ds = new DataSet();
da.Fill(ds, "studentdata");
L = new CheckBox[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
{
L[i] = new CheckBox();
L[i].Text = ds.Tables[0].Rows[i].ItemArray.GetValue(0).ToString();
L[i].Location = new Point(100, x);
this.Controls.Add(L[i]);
}
int X=50;
CheckBox[] L;
SqlConnection con = new SqlConnection("user id=sa;password=;database=college");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter("select * from studentdata", con);
DataSet ds = new DataSet();
da.Fill(ds, "studentdata");
L = new CheckBox[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
{
L[i] = new CheckBox();
L[i].Text = ds.Tables[0].Rows[i].ItemArray.GetValue(0).ToString();
L[i].Location = new Point(100, x);
this.Controls.Add(L[i]);
}
Monday, September 27, 2010
Removing the Last Character of String
Here my requirement is "I need to remove the last character of the string ". I search for this and i found a solution to remove the last character of a string by using TrimEnd(',') method , means which character you want want to remove place that end of the character in between single cottation
Ex: here i am adding two textboxes text and i am removing ,(camma) at the end of the combined text
string CCAddress= CC.Text + "," + CC2.Text; //adding two textboxes text into CCAddress
string CCadd = CCAddress.TrimEnd(','); //removing the , at the end
More About Trim Method :
You can easily remove white spaces from both ends of a string using the String.Trim method, as shown in the following code example.
The String.TrimEnd method removes characters from the end of a string, creating a new string object. An array of characters is passed to this method to specify the characters to be removed. The order of the elements in the character array does not affect the trim operation. The trim stops when a character not specified in the array is found.
The following code example removes the last letters of a string using the TrimEnd method. In this example, the position of the 'r' character and the 'W' character are reversed to illustrate that the order of characters in the array does not matter. Notice that this code removes the last word of myString plus part of the first.
The following code example removes the last word of a string using the TrimEnd method. In this code, a comma follows the word Hello and, because the comma is not specified in the array of characters to trim, the trim ends at the comma.
The String.TrimStart method is similar to the String.TrimEnd method except that it creates a new string by removing characters from the beginning of an existing string object. An array of characters is passed to the TrimStart method to specify the characters to be removed. As with the TrimEnd method, the order of the elements in the character array does not affect the trim operation. The trim stops when a character not specified in the array is found.
The following code example removes the first word of a string. In this example, the position of the 'l' character and the 'H' character are reversed to illustrate that the order of characters in the array does not matter.
The String.Remove method, beginning at a specified position in an existing string, removes a specified number of characters. This method assumes a zero-based index.
The following code example removes six characters from a string beginning at position five of a zero-based index of the string.
Ex: here i am adding two textboxes text and i am removing ,(camma) at the end of the combined text
string CCAddress= CC.Text + "," + CC2.Text; //adding two textboxes text into CCAddress
string CCadd = CCAddress.TrimEnd(','); //removing the , at the end
More About Trim Method :
Trimming and Removing Characters
If you are parsing a sentence into individual words, you might end up with words that have blank spaces ( also called white spaces ) on either end of the word. In this situation, you can use one of the trim methods in the System.String class to remove any number of spaces or other characters from a specified position in the string. The following table describes the available trim methods.Method Name | Use | ||||||||
---|---|---|---|---|---|---|---|---|---|
String.Trim | Removes white spaces from the beginning and end of a string. | ||||||||
String.TrimEnd | Removes characters specified in an array of characters from the end of a string. | ||||||||
String.TrimStart | Removes characters specified in an array of characters from the beginning of a string. | ||||||||
String.Remove | Removes a specified number of characters from a specified index position in a string. |
Trim
[ VB ] Dim myString As String = " Big " Console.WriteLine ( "Hello{0}World!", myString ) Dim TrimString As String = myString.Trim ( ) Console.WriteLine ( "Hello{0}World!", TrimString )
[ C# ]
String myString = " Big ";
Console.WriteLine ( "Hello{0}World!", myString );
string TrimString = myString.Trim ( );
Console.WriteLine ( "Hello{0}World!", TrimString );
This code displays the following lines to the console:Hello Big World! HelloBigWorld!
TrimEnd
The following code example removes the last letters of a string using the TrimEnd method. In this example, the position of the 'r' character and the 'W' character are reversed to illustrate that the order of characters in the array does not matter. Notice that this code removes the last word of myString plus part of the first.
[ VB ] Dim myString As String = "Hello World!" Dim myChar As Char ( ) = {"r"c, "o"c, "W"c, "l"c, "d"c, "!"c, " "c } Dim NewString As String = myString.TrimEnd ( myChar ) Console.WriteLine ( NewString )
[ C# ]
string myString = "Hello World!";
char [ ] myChar = {'r','o','W','l','d','!',' '};
string NewString = myString.TrimEnd ( myChar );
Console.WriteLine ( NewString );
This code displays He to the console. The following code example removes the last word of a string using the TrimEnd method. In this code, a comma follows the word Hello and, because the comma is not specified in the array of characters to trim, the trim ends at the comma.
[ VB ] Dim myString As String = "Hello, World!" Dim myChar As Char ( ) = {"r"c, "o"c, "W"c, "l"c, "d"c, "!"c, " "c } Dim NewString As String = myString.TrimEnd ( myChar ) Console.WriteLine ( NewString )
[ C# ]
string myString = "Hello, World!";
char [ ] myChar = {'r','o','W','l','d','!',' '};
string NewString = myString.TrimEnd ( myChar );
Console.WriteLine ( NewString );
This code displays Hello, to the console. TrimStart
The following code example removes the first word of a string. In this example, the position of the 'l' character and the 'H' character are reversed to illustrate that the order of characters in the array does not matter.
[ VB ]
Dim myString As String = "Hello World!"
Dim myChar As Char ( ) = {"e"c, "H"c, "l"c, "o"c, " "c}
Dim NewString As String = myString.TrimStart ( myChar )
Console.WriteLine ( NewString )
[ C# ]
string myString = "Hello World!";
char [ ] myChar = {'e', 'H','l','o',' ' };
string NewString = myString.TrimStart ( myChar );
Console.WriteLine ( NewString );
This code displays World! to the console. Remove
The following code example removes six characters from a string beginning at position five of a zero-based index of the string.
[ VB ] Dim myString As String = "Hello Beautiful World!" Console.WriteLine ( myString.Remove ( 5, 10 ) )
[ C# ]
string myString = "Hello Beautiful World!";
Console.WriteLine ( myString.Remove ( 5,10 ) );
This code displays Hello World! to the console.
Add Items to Populate ASP.Net CheckBoxList Control Dynamically
The ASP.Net CheckBoxList control also provides the method to populate it by adding the list items dynamically using C# code. You can use the Add method of Items collection property of CheckBoxList control to populate the items programmatically. The Items property gets the collection of list items stored in the CheckBoxList control. It belongs to the ListItemCollection class and provides the read-only member of this collection class. The Items property further enables you to access the public methods of ListItemCollection class that allow you to add or remove the list items. Here we will use the Add method to populate the list items into the CheckBoxList control.
Following are the two overloaded ways of using the Add method of Items collection property of CheckBoxList:
1.[CheckBoxList].Items.Add( ListItem item );
It allows you to add the specified list item at the end of CheckBoxList collection. You can use the well suited overloaded way of ListItem class constructor to add a new item.
2.[CheckBoxList].Items.Add( string text );
It appends the collection of list items of CheckBoxList control by adding the specified string at the end of collection.
For adding the ListItem using first overloaded Add method you can use the following overloaded constructor of ListItem class:
It allows you to add the ListItem with its text that will appear in the CheckBoxList control along with its value that will work at the back end.
Example:
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
C# Code:
There are different ways to add the List Items into the CheckBoxList control. In the following samples we have shown 2 different ways to add the ListItems:
Example 1:
Populate CheckBoxList Control Items Dynamically
Following are the two overloaded ways of using the Add method of Items collection property of CheckBoxList:
1.[CheckBoxList].Items.Add( ListItem item );
It allows you to add the specified list item at the end of CheckBoxList collection. You can use the well suited overloaded way of ListItem class constructor to add a new item.
2.[CheckBoxList].Items.Add( string text );
It appends the collection of list items of CheckBoxList control by adding the specified string at the end of collection.
For adding the ListItem using first overloaded Add method you can use the following overloaded constructor of ListItem class:
new ListItem( string text, string value );
Example:
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
C# Code:
There are different ways to add the List Items into the CheckBoxList control. In the following samples we have shown 2 different ways to add the ListItems:
Example 1:
ListItemCollection itemsCollection = CheckBoxList1.Items;
itemsCollection.Add(new ListItem("item 1", "1"));
itemsCollection.Add(new ListItem("item 2", "2"));
itemsCollection.Add(new ListItem("item 3", "3"));
itemsCollection.Add(new ListItem("item 4", "4"));
itemsCollection.Add(new ListItem("item 5", "5"));
Example 2:itemsCollection.Add(new ListItem("item 1", "1"));
itemsCollection.Add(new ListItem("item 2", "2"));
itemsCollection.Add(new ListItem("item 3", "3"));
itemsCollection.Add(new ListItem("item 4", "4"));
itemsCollection.Add(new ListItem("item 5", "5"));
CheckBoxList1.Items.Add(new ListItem("item 1", "1"));
CheckBoxList1.Items.Add(new ListItem("item 2", "2"));
CheckBoxList1.Items.Add(new ListItem("item 3", "3"));
CheckBoxList1.Items.Add(new ListItem("item 4", "4"));
CheckBoxList1.Items.Add(new ListItem("item 5", "5"));
You can build your logic to add the ListItems into the ListItemCollection of CheckBoxList control using any of the above C# code. You can also use C# for loop to add the items that will also reduce the code lines.CheckBoxList1.Items.Add(new ListItem("item 2", "2"));
CheckBoxList1.Items.Add(new ListItem("item 3", "3"));
CheckBoxList1.Items.Add(new ListItem("item 4", "4"));
CheckBoxList1.Items.Add(new ListItem("item 5", "5"));
Output:
Get the output for above discussed code from the following link:Populate CheckBoxList Control Items Dynamically
CheckBoxList Control In ASP.NET
Getting CheckBoxList Selected Item Values into Text Box:
ASPX File Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
<asp:ListItem>d</asp:ListItem>
</asp:CheckBoxList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
.CS Code:
We want to write code in CheckBoxList1_SelectedIndexChange Event
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = string.Empty;
foreach (ListItem listitem in CheckBoxList1.Items)
{
if (listitem.Selected)
TextBox1.Text += listitem.Text + ",";
}
}
OUTPUT:
Get the output for above discussed code from the following link:
CheckBoxList Control Selected Items
ASPX File Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
<asp:ListItem>d</asp:ListItem>
</asp:CheckBoxList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
.CS Code:
We want to write code in CheckBoxList1_SelectedIndexChange Event
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = string.Empty;
foreach (ListItem listitem in CheckBoxList1.Items)
{
if (listitem.Selected)
TextBox1.Text += listitem.Text + ",";
}
}
OUTPUT:
Get the output for above discussed code from the following link:
CheckBoxList Control Selected Items
Validate More than One Email Address in a TextBox In ASP.NET by using JavaScript
Single E-Mail Address Validation using JavaScript
JavaScript Function:
<script language = "Javascript">
function Validateemail()
{
var emailaddress = document.getElementById('<%=txtEmail.ClientID %>').value;
var isValidEmail = true;
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
isValidEmail = emailPattern.test(emailaddress);
if (isValidEmail == false)
{
alert("invalide Email Address");
return false;
}
else
{
return true;
}
}
</script>
HTML Form Coding
<form name="frmSample" method="post" action="#" onSubmit="return Validateemail()">
<p>Enter an Email Address :
<input type="text" name="txtEmail">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
Check Functionality Below:
Saturday, September 18, 2010
Programming Basics
Variables. Data Types.
The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting program just to obtain a simple sentence written on the screen as result. It certainly would have been much faster to type the output sentence by ourselves. However, programming is not limited only to printing simple texts on the screen. In order to go a little further on and to become able to write programs that perform useful tasks that really save us work we need to introduce the concept of variable.
Let us think that I ask you to retain the number 5 in your mental memory, and then I ask you to memorize also the number 2 at the same time. You have just stored two different values in your memory. Now, if I ask you to add 1 to the first number I said, you should be retaining the numbers 6 (that is 5+1) and 2 in your memory. Values that we could now for example subtract and obtain 4 as result.
The whole process that you have just done with your mental memory is a simile of what a computer can do with two variables. The same process can be expressed in C++ with the following instruction set:
Obviously, this is a very simple example since we have only used two small integer values, but consider that your computer can store millions of numbers like these at the same time and conduct sophisticated mathematical operations with them.
Therefore, we can define a variable as a portion of memory to store a determined value.
Each variable needs an identifier that distinguishes it from the others. For example, in the previous code the variable identifiers were
Another rule that you have to consider when inventing your own identifiers is that they cannot match any keyword of the C++ language nor your compiler's specific ones, which are reserved keywords. The standard reserved keywords are:
Additionally, alternative representations for some operators cannot be used as identifiers since they are reserved words under some circumstances:
Your compiler may also include some additional specific reserved keywords.
Very important: The C++ language is a "case sensitive" language. That means that an identifier written in capital letters is not equivalent to another one with the same name but written in small letters. Thus, for example, the
The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer (generally an integer between 0 and 255). In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers.
Next you have a summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one:
* The values of the columns Size and Range depend on the system the program is compiled for. The values shown above are those found on most 32-bit systems. But for other systems, the general specification is that
These are two valid declarations of variables. The first one declares a variable of type int with the identifier a. The second one declares a variable of type float with the identifier mynumber. Once declared, the variables a and mynumber can be used within the rest of their scope in the program.
If you are going to declare more than one variable of the same type, you can declare all of them in a single statement by separating their identifiers with commas. For example:
This declares three variables (a, b and c), all of them of type int, and has exactly the same meaning as:
The integer data types char, short, long and int can be either signed or unsigned depending on the range of numbers needed to be represented. Signed types can represent both positive and negative values, whereas unsigned types can only represent positive values (and zero). This can be specified by using either the specifier signed or the specifier unsigned before the type name. For example:
By default, if we do not specify either signed or unsigned most compiler settings will assume the type to be signed, therefore instead of the second declaration above we could have written:
with exactly the same meaning (with or without the keyword
An exception to this general rule is the char type, which exists by itself and is considered a different fundamental data type from signed char and unsigned char, thought to store characters. You should use either
Finally,
To see what variable declarations look like in action within a program, we are going to see the C++ code of the example about your mental memory proposed at the beginning of this section:
Do not worry if something else than the variable declarations themselves looks a bit strange to you. You will see the rest in detail in coming sections.
A variable can be either of global or local scope. A global variable is a variable declared in the main body of the source code, outside all functions, while a local variable is one declared within the body of a function or a block.
Global variables can be referred from anywhere in the code, even inside functions, whenever it is after its declaration.
The scope of local variables is limited to the block enclosed in braces (
The first one, known as c-like initialization, is done by appending an equal sign followed by the value to which the variable will be initialized:
For example, if we want to declare an int variable called a initialized with a value of 0 at the moment in which it is declared, we could write:
The other way to initialize variables, known as constructor initialization, is done by enclosing the initial value between parentheses (
For example:
Both ways of initializing variables are valid and equivalent in C++.
The C++ language library provides support for strings through the standard
A first difference with fundamental data types is that in order to declare and use objects (variables) of this type we need to include an additional header file in our source code:
As you may see in the previous example, strings can be initialized with any valid string literal just like numerical type variables can be initialized to any valid numerical literal. Both initialization formats are valid with strings:
Strings can also perform all the other basic operations that fundamental data types can, like being declared without an initial value and being assigned values during execution:
The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting program just to obtain a simple sentence written on the screen as result. It certainly would have been much faster to type the output sentence by ourselves. However, programming is not limited only to printing simple texts on the screen. In order to go a little further on and to become able to write programs that perform useful tasks that really save us work we need to introduce the concept of variable.
Let us think that I ask you to retain the number 5 in your mental memory, and then I ask you to memorize also the number 2 at the same time. You have just stored two different values in your memory. Now, if I ask you to add 1 to the first number I said, you should be retaining the numbers 6 (that is 5+1) and 2 in your memory. Values that we could now for example subtract and obtain 4 as result.
The whole process that you have just done with your mental memory is a simile of what a computer can do with two variables. The same process can be expressed in C++ with the following instruction set:
1 2 3 4 |
|
Obviously, this is a very simple example since we have only used two small integer values, but consider that your computer can store millions of numbers like these at the same time and conduct sophisticated mathematical operations with them.
Therefore, we can define a variable as a portion of memory to store a determined value.
Each variable needs an identifier that distinguishes it from the others. For example, in the previous code the variable identifiers were
a
, b
and result
, but we could have called the variables any names we wanted to invent, as long as they were valid identifiers.Identifiers
A valid identifier is a sequence of one or more letters, digits or underscore characters (_
). Neither spaces nor punctuation marks or symbols can be part of an identifier. Only letters, digits and single underscore characters are valid. In addition, variable identifiers always have to begin with a letter. They can also begin with an underline character (_
), but in some cases these may be reserved for compiler specific keywords or external identifiers, as well as identifiers containing two successive underscore characters anywhere. In no case they can begin with a digit.Another rule that you have to consider when inventing your own identifiers is that they cannot match any keyword of the C++ language nor your compiler's specific ones, which are reserved keywords. The standard reserved keywords are:
asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while
Additionally, alternative representations for some operators cannot be used as identifiers since they are reserved words under some circumstances:
and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq
Your compiler may also include some additional specific reserved keywords.
Very important: The C++ language is a "case sensitive" language. That means that an identifier written in capital letters is not equivalent to another one with the same name but written in small letters. Thus, for example, the
RESULT
variable is not the same as the result
variable or the Result
variable. These are three different variable identifiers.Fundamental data types
When programming, we store the variables in our computer's memory, but the computer has to know what kind of data we want to store in them, since it is not going to occupy the same amount of memory to store a simple number than to store a single letter or a large number, and they are not going to be interpreted the same way.The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer (generally an integer between 0 and 255). In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers.
Next you have a summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one:
Name | Description | Size* | Range* |
---|---|---|---|
char | Character or small integer. | 1byte | signed: -128 to 127 unsigned: 0 to 255 |
short int ( short ) | Short Integer. | 2bytes | signed: -32768 to 32767 unsigned: 0 to 65535 |
int | Integer. | 4bytes | signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 |
long int ( long ) | Long integer. | 4bytes | signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 |
bool | Boolean value. It can take one of two values: true or false. | 1byte | true or false |
float | Floating point number. | 4bytes | +/- 3.4e +/- 38 (~7 digits) |
double | Double precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
long double | Long double precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
wchar_t | Wide character. | 2 or 4 bytes | 1 wide character |
* The values of the columns Size and Range depend on the system the program is compiled for. The values shown above are those found on most 32-bit systems. But for other systems, the general specification is that
int
has the natural size suggested by the system architecture (one "word") and the four integer types char
, short
, int
and long
must each one be at least as large as the one preceding it, with char
being always one byte in size. The same applies to the floating point types float
, double
and long double
, where each one must provide at least as much precision as the preceding one.Declaration of variables
In order to use a variable in C++, we must first declare it specifying which data type we want it to be. The syntax to declare a new variable is to write the specifier of the desired data type (like int, bool, float...) followed by a valid variable identifier. For example:1 2 |
|
These are two valid declarations of variables. The first one declares a variable of type int with the identifier a. The second one declares a variable of type float with the identifier mynumber. Once declared, the variables a and mynumber can be used within the rest of their scope in the program.
If you are going to declare more than one variable of the same type, you can declare all of them in a single statement by separating their identifiers with commas. For example:
|
This declares three variables (a, b and c), all of them of type int, and has exactly the same meaning as:
1 2 3 |
|
The integer data types char, short, long and int can be either signed or unsigned depending on the range of numbers needed to be represented. Signed types can represent both positive and negative values, whereas unsigned types can only represent positive values (and zero). This can be specified by using either the specifier signed or the specifier unsigned before the type name. For example:
1 2 |
|
By default, if we do not specify either signed or unsigned most compiler settings will assume the type to be signed, therefore instead of the second declaration above we could have written:
|
with exactly the same meaning (with or without the keyword
signed
)An exception to this general rule is the char type, which exists by itself and is considered a different fundamental data type from signed char and unsigned char, thought to store characters. You should use either
signed
or unsigned
if you intend to store numerical values in a char-sized variable.short
and long
can be used alone as type specifiers. In this case, they refer to their respective integer fundamental types: short
is equivalent to short int
and long
is equivalent to long int
. The following two variable declarations are equivalent:1 2 |
|
Finally,
signed
and unsigned
may also be used as standalone type specifiers, meaning the same as signed int
and unsigned int
respectively. The following two declarations are equivalent: 1 2 |
|
To see what variable declarations look like in action within a program, we are going to see the C++ code of the example about your mental memory proposed at the beginning of this section:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
| 4 |
Do not worry if something else than the variable declarations themselves looks a bit strange to you. You will see the rest in detail in coming sections.
Scope of variables
All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous code at the beginning of the body of the function main when we declared that a, b, and result were of type int.A variable can be either of global or local scope. A global variable is a variable declared in the main body of the source code, outside all functions, while a local variable is one declared within the body of a function or a block.
Global variables can be referred from anywhere in the code, even inside functions, whenever it is after its declaration.
The scope of local variables is limited to the block enclosed in braces (
{}
) where they are declared. For example, if they are declared at the beginning of the body of a function (like in function main) their scope is between its declaration point and the end of that function. In the example above, this means that if another function existed in addition to main, the local variables declared in main could not be accessed from the other function and vice versa.Initialization of variables
When declaring a regular local variable, its value is by default undetermined. But you may want a variable to store a concrete value at the same moment that it is declared. In order to do that, you can initialize the variable. There are two ways to do this in C++:The first one, known as c-like initialization, is done by appending an equal sign followed by the value to which the variable will be initialized:
type identifier = initial_value ;
For example, if we want to declare an int variable called a initialized with a value of 0 at the moment in which it is declared, we could write:
|
The other way to initialize variables, known as constructor initialization, is done by enclosing the initial value between parentheses (
()
): type identifier (initial_value) ;
For example:
|
Both ways of initializing variables are valid and equivalent in C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
| 6 |
Introduction to strings
Variables that can store non-numerical values that are longer than one single character are known as strings.The C++ language library provides support for strings through the standard
string
class. This is not a fundamental type, but it behaves in a similar way as fundamental types do in its most basic usage.A first difference with fundamental data types is that in order to declare and use objects (variables) of this type we need to include an additional header file in our source code:
<string>
and have access to the std
namespace (which we already had in all our previous programs thanks to the using namespace
statement).1 2 3 4 5 6 7 8 9 10 11 |
| This is a string |
As you may see in the previous example, strings can be initialized with any valid string literal just like numerical type variables can be initialized to any valid numerical literal. Both initialization formats are valid with strings:
1 2 |
|
Strings can also perform all the other basic operations that fundamental data types can, like being declared without an initial value and being assigned values during execution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| This is the initial string content This is a different string content |
Friday, September 17, 2010
.NET Certification Guidence
What is MCTS?
MCTS stands for Microsoft Certified Technology Specialist and is a new wave of Microsoft certifications aimed at helping candidates certify their skills in a specific technology. Each MCTS certification, whether it be .NET Framework 3.5 ASP.NET Applications, or Microsoft SQL Server 2008, Implementation and Maintenance, consists of one or more exams. Candidates must pass all exams to achieve the certification. Exam do not have to be taken in any particular order, but it usually makes sense to take them from foundation leading up to the more advanced.Candidates must pass the specified number of exams to earn the certification. Using .NET Framework 3.5, ASP.NET Applications as an example, candidates must pass the following exams:
- Exam 70-536: TS: Microsoft .NET Framework – Application Development Foundation
- Exam 70-562: TS: Microsoft .NET Framework 3.5, ASP.NET Application Development
MCTS is also the building block for other certifications such as MCPD and MCITP. Once you have earned the MCTS certification you are usually just an exam or two away from achieving a higher certification such as MCPD: ASP.NET Developer 3.5. The online Microsoft Certification Planner is a great tool to plan your next exam and certification. The planner shows your current status and automatically calculates potential certifications for you.
All Microsoft exams are conducted through the Prometric testing provider. You must book your exam online using their website, you'll also have to pay the fees online. Your actual exam will be based at one of the many testing centres around the world, where you must attend in person. All professional Microsoft exams such as MCTS are computer based and consist of a variety of testing methods.
Once you have passed your Microsoft exam, you'll receive the Welcome Pack through the post (make sure you login to the MCP Member Site and confirm your address so Microsoft will send the pack). You'll receive a badge, certification and even a letter from Mr Gates himself!
What is MCPD?
MCPD stands for Microsoft Certified Professional Developer and is regarded as a high level and highly accredited certification. MCPD allows developers to demonstrate their ability to use Microsoft Visual Studio and the Microsoft .NET Framework to excel in a real-world job role. The MCPD cert, validates a comprehensive set of skills required to be successful on the job, and gives hiring managers and potential customers a reliable indicator of your job performance.
Building on top of the existing MCTS certification path, MCPD takes the candidates skills one step further and focuses on high level design and implementation to build .NET solutions. The MCPD certification exists for both .NET 2.0 and .NET 3.5. Candidates choose the specific version of MCPD based on whether they use Visual Studio 2005 or Visual Studio 2008.
Candidates must first complete the MCTS certification path before they can achieve the MCPD. Depending on the MCPD chosen, you will have to pass a single exam or 2 for the Enterprise level.
Using MCPD ASP .NET Developer 3.5 as an example, candidates must pass the following exams:
- Exam 70-564: PRO: Designing and Developing ASP.NET Applications Using Microsoft .NET Framework 3.5
If you already hold the MCPD for .NET 2.0, you can take any of the following upgrade exams to move to the .NET 3.5 version of the MCPD:
- Windows Developer: Exam 70-566: Upgrade: Transition your MCPD Windows Developer Skills to MCPD Windows Developer 3
- Web Developer: Exam 70-567: Upgrade: Transition your MCPD Web Developer Skills to MCPD ASP.NET Developer 3.5
- Enterprise: Exam 70-568: Upgrade: Transition your MCPD Enterprise Application Developer Skills to MCPD Enterprise Applications Developer 3.5, Part 1 AND Exam 70-569: Upgrade: Transition your MCPD Enterprise Application Developer Skills to MCPD Enterprise Applications Developer 3.5, Part 2
All Microsoft exams are conducted through the Prometric testing provider. You must book your exam online using the Prometric website, you'll also have to pay the fees online. Fess vary per country, but are usually close to the US fee of $125. Your actual exam will be based at one of the many testing centres around the world, where you must attend in person. You can choose the testing centre and time of the exam through the Prometric site. All professional Microsoft exams such as MCPD are computer based and consist of a variety of testing methods.
Once you have achieved your Microsoft certification, you'll receive the Welcome Pack through the post (make sure you login to the MCP Member Site and confirm your address so Microsoft will send the pack). You'll receive a badge, certification and even a letter from Mr Gates himself!
How can I earn an MCPD?
To earn an MCPD certification you will need to pass 3 or 5 exams in the MCPD series. Depending on the type of MCPD certification you want to go for (windows, web or enterprise) you will need to pass the appropriate exams below.
Remember, that even if you achieve the MCPD Windows Developer or MCPD Web Developer, you can still continue to take more exams and achieve the Enterprise Application Developer certification.Visual Studio 2008
Windows Developer 3.5 on Visual Studio 2008
MCTS Prerequisite: TS: Microsoft .NET Framework – Application Development Foundation
Exam 70-536
MCTS Prerequisite: TS: Microsoft .NET Framework 3.5 – Windows Forms Application Development
Exam 70-505
MCPD Requirement: PRO: Designing and Developing Windows Applications Using the Microsoft .NET Framework 3.5
Exam 70-563
ASP.NET Developer 3.5 on Visual Studio 2008
MCTS Prerequisite: TS: Microsoft .NET Framework – Application Development Foundation
Exam 70-536
MCTS Prerequisite: TS: Microsoft .NET Framework 3.5, ASP.NET Application Development
Exam 70-562
MCPD Requirement: PRO: Designing and Developing ASP.NET Applications Using the Microsoft .NET Framework 3.5
Exam 70-564
Enterprise Application Developer 3.5 on Visual Studio 2008
MCTS Prerequisite: TS: Microsoft .NET Framework – Application Development Foundation
Exam 70-536
MCTS Prerequisite: TS: Microsoft .NET Framework 3.5 – Windows Forms Application Development
Exam 70-505
MCTS Prerequisite: TS: Microsoft .NET Framework 3.5, ASP.NET Application Development
Exam 70-562
MCTS Prerequisite: TS: Microsoft .NET Framework 3.5, ADO.NET Application Development
Exam 70-561
MCTS Prerequisite: TS: Microsoft .NET Framework 3.5 – Windows Communication Foundation Application Development
Exam 70-503
MCPD Requirement: PRO: Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5
Exam 70-565
Visual Studio 2005
Windows Developer on Visual Studio 2005
MCTS prerequisite: TS: Microsoft .NET Framework – Application Development Foundation
Exam 70-536
MCTS prerequisite: TS: Microsoft .NET Framework 2.0 – Windows-Based Client Development
Exam 70-526
MCPD requirement: PRO: Designing and Developing Windows Applications by Using the Microsoft .NET Framework
Exam 70-548
Web Developer on Visual Studio 2005
MCTS prerequisite: TS: Microsoft .NET Framework – Application Development Foundation
Exam 70-536
MCTS prerequisite: TS: Microsoft .NET Framework 2.0 – Web-Based Client Development
Exam 70-528
MCPD requirement: PRO: Designing and Developing Web-Based Applications by Using the Microsoft .NET Framework
Exam 70-547
Enterprise Application Developer on Visual Studio 2005
MCTS prerequisite: TS: Microsoft .NET Framework – Application Development Foundation
Exam 70-536
MCTS prerequisite: TS: Microsoft .NET Framework 2.0 – Windows-Based Client Development
Exam 70-526
MCTS prerequisite: TS: Microsoft .NET Framework 2.0 – Web-Based Client Development
Exam 70-528
MCTS prerequisite: TS: Microsoft .NET Framework 2.0 – Distributed Application Development
Exam 70-529
MCPD requirement: PRO: Designing and Developing Enterprise Applications by Using the Microsoft .NET Framework
Exam 70-549
15% off coupon from MS Press
If you have chosen to buy one of the Microsoft Press books for your study material then you'll be pleased to know that at the back of the book there is a 15% off coupon. This voucher can be used against any MCP exam that you choose to book. Once you have used the voucher, it can't be used again or given to a friend.
To use the 15% off voucher:
- Simply use the Prometric site as normal to choose your exam and test center
- When you reach the payment page, enter the 15% off coupon code
- The discounted price will be shown against the total cost of the exam
- Continue paying for the exam as normal
Note: You cannot use the 15% off voucher with the Second Shot offer.
What is the Second Shot offer?
The Microsoft 2nd shot offer is a great offer for anyone taking an MCP exam. The voucher allows you to retake an exam for free if you do not pass the exam the first time of trying.
When you schedule your exam, simply enter the second shot voucher number in the Prometric website. If you do not pass the exam, the next time you schedule the exam it will be for free.
What if I forget to use the voucher?
Don't worry, you can cancel the exam (as long as you are within the cancellation period) and reschedule it using the 2nd shot voucher. The cancellation period is usually 48 hours before the exam date. If you unsure, contact Prometric and explain your situation. They usually reply within a day or so.
Where to get the 2nd shot voucher
The 2nd shot voucher is specific to each candidate, so you need to register for the voucher using your email address. Visit the Microsoft Learning site and search for 2nd shot voucher. The current offer ends June 30, 2009. But Microsoft have reintroduced the offer on several other occasions so it wont disappear anytime soon.
The offer is valid on any Microsoft IT Professional, developer, or project manager certification exam.
How long must I wait to retake an exam
Microsoft has a set retake policy which applies to all their certification exams. These retake policies are in place to help protect the integrity of Microsoft exams from illegal copying and distribution. Microsoft is determined to stamp out braindump sites which are used to help people cheat their way through exams.
If you are unfortunate enough to fail an exam, do not worry as you can usually take the exam within a short period. This does not apply to Beta exams. See below.
Microsoft's retake policy is as follows:
General MCP Exam Retake Policy
1. If a you do not pass an exam the first time, you may retake it after at least 24 hours have passed.
2. If you do not achieve a passing score the second time, you must wait at least 14 days to retake the exam for a third time.
3. The same 14 day waiting period will be applied to all your subsequent exam retakes.
4. You are not allowed to take any exam any more than five times in a single year. If you do want to take an exam more than five times a year, then you must obtain permission from Microsoft.
5. If you have already passed an exam you cannot take it again.
If you are thinking of taking MCP beta exams then the following Microsoft retake policy applies
1. Beta exams can be taken only once, ever.
2. This policy supersedes the general retake policy and tales precedence.
A beta exam is an early release of an exam that is not available to the general public. You may volunteer to take a beta exam, but you must accept the fact that questions are in their infancy and some may be incorrect. Beta exams are usually released well before the official exam date so that Microsoft can fine tune the questions following your feedback.
Free .NET Certification Practice Test
Free Microsoft Practice Exams - MCPD, MCTS, MCITP, MCSA, MCSE
All of the following Microsoft practice exams are 100% free for all users. Our Exams target the following Microsoft certifications - MCITP, MCSE, MCSA, MCPD, MCTS and MCSD.
Our free online Microsoft practice exams are written by our team of software professionals who have worked with Microsoft.NET technologies for well over 5 years. The questions are specifically selected to provide a practice exam that aids your Microsoft training. Each exam consists of 20 random questions selected from a pool of 50+ questions!
We are developing new exams all the time, the following exams are in development and will be ready very soon..
All of the following Microsoft practice exams are 100% free for all users. Our Exams target the following Microsoft certifications - MCITP, MCSE, MCSA, MCPD, MCTS and MCSD.
Our free online Microsoft practice exams are written by our team of software professionals who have worked with Microsoft.NET technologies for well over 5 years. The questions are specifically selected to provide a practice exam that aids your Microsoft training. Each exam consists of 20 random questions selected from a pool of 50+ questions!
We are developing new exams all the time, the following exams are in development and will be ready very soon..
In Development
70-682 (New) : Upgrade to MCITP Windows 7 EDST | Start Exam |
70-667 (New) : MCTS SharePoint 2010 Configuring | Start Exam |
70-668 (New) : MCITP SharePoint 2010 Administrator | Start Exam |
70-685 (New) : MCITP Windows 7, Enterprise Desktop Support Technician | Start Exam |
70-680 (New) : TS: Windows 7 Configuring (MCTS) | Start Exam |
70-504 (New) : TS: Microsoft .NET Framework 3.5 - Windows Workflow Foundation | Start Exam |
70-503 (New) : TS: Microsoft .NET Framework 3.5 - Windows Communication Foundation | Start Exam |
70-453 (New) : MCITP Upgrading your SQL Server 2005 DBA to MCITP SQL Server 2008. | Start Exam |
70-432 (New) : MCTS SQL Server 2008 – Implementation and Maintenance (MCTS) | Start Exam |
70-450 (New) : Designing, optimizing and maintaining a database server infrastructure using Microsoft SQL Server 2008 (MCITP) | Start Exam |
70-640 (New) : TS: Windows Server 2008 Active Directory, Configuring (MCITP, MCTS) | Start Exam |
70-561 (New) : TS: Microsoft .NET Framework 3.5, ADO.NET Application Development (MCTS, MCPD) | Start Exam |
70-562 (New) : TS: Microsoft .NET Framework 3.5, ASP.NET Application Development (MCTS, MCPD) | Start Exam |
70-291 : Implementing, Managing, and Maintaining a Microsoft Windows Server 2003 Network Infrastructure (MCSE, MCSA) | Start Exam |
70-290 : Managing and Maintaining a Windows Server 2003 Environment (Part of the MCSE, MCSA group) | Start Exam |
70-270 : Installing, Configuring, and Administering Microsoft Windows XP Professional (Part of the MCSE, MCSA group) | Start Exam |
70-620 : TS: Windows Vista, Configuring (Part of the MCTS, MCITP groups) | Start Exam |
70-536 : TS: Microsoft .NET Framework 2.0 ”Application Development Foundation (Part of the MCTS, MCPD groups) | Start Exam |
70-552 : UPGRADE: MCAD Skills to MCPD Windows Developer by Using the Microsoft .NET Framework | Start Exam |
70-526 : Microsoft .NET Framework 2.0 - Windows-Based Client Development (MCPD Windows Developer) | Start Exam |
70-528 : Microsoft .NET Framework 2.0 - Web-based Client Development (MCPD Web Developer) | Start Exam |
Subscribe to:
Posts (Atom)