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







Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook