Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Tuesday, 11 February 2014

XML Documentation in C#

In C#, we use XML Comments for creating documentation for Classes and its member. XML Documentation helps other programmer or developer to use your code i.e. Classes, Functions and its member easily by providing some useful information. XML Documentation starts with three slashes before the class or function going to be documented.

Adding XML Documentation to a class:

Typing three slashes (///) before a class or function will create documentation automatically in Visual Studio. Documentation contain one or more than one documentation elements. Each element starts with start tag (e.g. <summary>) and ends with end tag (e.g. </summary>).
Element
Description
<summary>
Provide Description for Class, member etc.
<param name=”i”>
Describe a parameter of a method
<returns>
Describe return type of a method
<value>
Describe value of a property
For Example:-

In above example, when we type three slashes before result method than it will automatically create three documentation elements that are Summary (used for description of class), param tag for each parameter and return tag for method’s return type.

When I type or use Add class than, IntelliSense in Visual Studio show Screen tip that we have added in xml documentation element (<summary tag>) earlier.
Preview:

Protected by Copyscape Web Plagiarism Scanner



Friday, 7 February 2014

Creating and using DLL (Class library) in C#

A DLL (Dynamic Link library) is a library that contain some functions (code) and data which can be used by more than one program at a same time. Once we have created a DLL file, we can use it in many application. The only thing we have to do is to add the reference/Import the DLL File.


Creating DLL File:-
Step 1: Open Visual Studio -> Click on File->New Project -> Visual C# -> Class library

Step 2:- Change the class name(class1.cs) to calculate.cs

Step 3:- in calculate class write method for addition and subtraction of two integer.

Step 4:- Build the solution (F6). If Build is succeeded than you will see calculation.dll file in bin/debug directory of your project.
We have created our DLL file. Now we are going to use it in another Application.

Using DLL File:-
Step 1:- Open Visual Studio-> Click on File -> New Project ->Visual C# ->Windows Form Application
Step 2:- Design form as in below picture

Step 3:- Add Reference of dll file i.e. calculation.dll that we have created earlier.
Step: 4:- Add namespace (using calculation)




Step 5:-
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 Calculation;

namespace MiniCalculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        calculate cal = new calculate();
        //Addition Button click event
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //storing the result in int i
                int i = cal.Add(int.Parse(txtFirstNo.Text), int.Parse(txtSecNo.Text));
                txtResult.Text = i.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        //Subtraction button click event
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //storing the result in int i
                int i = cal.Sub(int.Parse(txtFirstNo.Text), int.Parse(txtSecNo.Text));
                txtResult.Text = i.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

Protected by Copyscape Web Plagiarism Scanner







Monday, 27 January 2014

Stitched Look using CSS

In this Article, we are going to learn how to give Stitched effect using CSS. Firstly, we give Stitched effect to a simple box (i.e. any div), then we add some background-images and take this trick to the next level.
Let's Begin:
Example1:
HTML Structure: 
<div class="stitched">Stitched</div> 
 
CSS:
.stitched
{
background-color:darkred;
width:200px;
font-size:20px;
color:white;
padding:20px;
}
Here we set background-color, width, Font-size, etc. of div using .stitched class.
 
Preview:
.stitched
{
background-color:darkred;
width:200px;
font-size:20px;
color:white;
padding:20px;
border:2px dashed white;
border-radius:20px;
box-shadow:0px 0px 4px 4px darkred;
}
Now, we added border, border-radius and box-shadow to .stitched class. In box shadow, we only use blur and spread and set value to 4px (box-shadow syntax: box-shadow: h-shadow v-shadow blur spread color). 
 
Preview:
This one is the basic example of giving stitched effect. Now we are going to create another Stitched effect.
 
Example2: 
HTML Structure: 
 
<div class="pic">
   <div class="borderdiv">
   <div class="inner"><p class="text1">Stitched</p></div>
   </div>
</div>
Here, the outermost div (.pic) is used to set background-image, middle (.borderdiv) to set border and giving stitched look and innermost div (.inner) for text, etc.
 
CSS:
.pic
{
background-image:url("white_leather.png");
width:302px;
height:202px;
border-radius:5px;
}
Here, I set background-image, width, height and border-radius.
 
Preview:
.borderdiv
{
width:280px;
height:180px;
border: 2px dashed #aaa;
border-radius:10px;
position:relative;
top:9px;
left:10px;
box-shadow: 0 0 0 1px #f5f5f5;
}
Here, we set width and height less than the .pic so that it comes inside it. Then, we set Border, Border-radius and box-shadow to give effect of Stitched. Using Position, we adjust position inside the div (.pic).
 
Preview:
.text1
{
margin-top:60px;
text-align:center;
font-size:50px;
color:gray;
}
Here we adjust Font-size, color, align, etc.
 
 
Preview (Final):

I have created some other examples using the same technique. You can download it for viewing or using.
 
Preview:
You can also download the source code from the below link:
Hope you Like it. Thanks




Sunday, 12 January 2014

Part:2:-Variable and Data Type

Part-2 Variable and Data type
Variable: 
A variable in program is specific piece of memory. Every variable in a program has a name. We use variable to store a data value in memory and retrieve the data that is stored in it.

Rules for giving a Name to variable:- (wrong declaration highlighted by red color)
a) A variable name only contains characters, digits and underscore. Variable names like oh! , Mike-Jack not allowed.

b) The first letter of variable name must be letter or underscore. Variable name must not be started with a digit like 8_oclock, 6_pack. Never try to start variable name with underscore because variable name started with underscore already declared in libraries which can cause quite confusion to understand.

c) No comma or blank space is provided within variable name.

d) Variable names are case-sensitive. If you declare length and Length are distinct.

e) Always try to give Variable name as short as possible and maximum of 31 characters. Giving large name will increase your typing effort.

f) You cannot provide C’s Keyword like main, switch as Variable name.



Data Type: 
Data type can be defined as type of data of variable. Whenever we declare a variable, we have to mention what kind of data it can hold or store. C offers Standard and minimal set of data type. Sometimes called as “Primitive Data Type”. 

For example:-
int num; //here int is Data Type
char name; //here char is Data Type

C language Data type can be classified into 3 type:-
1) Primary Data Type 2) Derived Data Type (e.g. Array, Pointer, Structure, Union) 3) User defined Data Type

Primary Data Type divided into four basic data types:-




Data Type
Description
Size(in byte)
Range
char
Character
1
-128 to +127
int
Integer
2 or 4
-32768 to +32767
float
Number with decimal point. Precision upto 6 digits
4
-3.4e38 to +3.4e38
Double
Number with decimal point. Precision upto 12 digits
8
-1.7e308 to +1.7e308

Size and Range of Data Type may vary according to the qualifiers. Data Type Qualifier can be divided into two part:-
1) Size Qualifier
2) Sign Qualifier

Size Qualifier: Size Qualifier alter the size of data type. There are 2 types of size qualifiers: short and long.
For Example:
Storage space or size of int data type is 4 byte for 32 bit processor. We can increase the range using long int whose size is 8 byte or decrease the size using short int whose size is 2 byte.

Sign Qualifier: Signed and unsigned keyword used to specify whether variable can store +ve number or +ve as well as –ve number.
Example:- unsigned int range is -32768 to +32767 whereas signed int range is 0 to 65,535

Example 2.1: Finding Size of Data Type using sizeof operator
#include <stdio.h>
#include <conio.h>
void main()
{
       printf("Size of char %d byte\n",sizeof(char));
       printf("Size of int %d byte\n",sizeof(int));
       printf("Size of float %d byte\n",sizeof(float));
       printf("Size of double %d byte\n",sizeof(double));
       getch();
}
On My system I get the following result


Constants:-
A Constant is used just like a variable, though its value never changes. For example: Value of π (pie) in trigonometry is fixed (constant) which is equal to 3.14159265.

We can declare constant in our program in two ways:-
1) Using #define    2) Using const keyword

Using #define:
#include <stdio.h>
#include <conio.h>
#define PI 3.14159f //defining name and value for PI
void main()
{
       float radius=2.2; //radius
       float circum=2*PI*radius; //variable storing circumference
       printf("Circumference of Circle=%f metre",circum); /*print the result on console or terminal*/
       getch();
}


Using const keyword:
#include <stdio.h>
#include <conio.h>
void main()
{
       const float PI=3.14159f; //declare PI using const
       float radius=2.2; //radius
       float circum=2*PI*radius; //variable storing circumference
       printf("Circumference of Circle=%f metre",circum); /*print the result on console or terminal*/
       getch();
}


When we use const keyword, we can specify a Data type for our constant where as in previous example (using # define), PI was just a sequence of characters that replace all the value of PI in your program.

Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook