How to view Intermediate Code in C# using Ildasm.Exe
Apr05

How to view Intermediate Code in C# using Ildasm.Exe

Welcome to CodeSpread! Hi guys, this is Sathish again, today let’s discuss how to view the intermediate code in c#. We know that CLR (Common Language Runtime) is used to convert the MSIL (Microsoft Intermediate Language) which is a pseudo code, into an executable program when a program runs. Knowing this, let’s discuss how to view MSIL using ILDASM.exe. MSIL Disassembler MSIL Disassembler is a companion tool to the MSIL Assembler (Ilasm.exe). Ildasm.exe takes a portable executable (PE) file that contains Microsoft intermediate language (MSIL) code and creates a text file suitable as input to Ilasm.exe. This tool is automatically installed with Visual Studio and with the Windows SDK. To run the tool, we recommend that you use the Visual Studio Command Prompt or the Windows SDK Command Prompt (CMD Shell). This is the Program where it returns the no of objects created for a class using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Chap1_3 { class Program { static int count; public Program() { ++count; } static void Main(string[] args) { Program p1 = new Program(); Program p2 = new Program(); Console.WriteLine("The No of Objects created for the class is : {0} ", count); Console.ReadKey(true); } } } // Output Now let’s see what will be the Intermediate code for this program using ildasm.exe, and then go to following path C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\ildasm.exe If u open ildasm.exe It will pop up with a new Window, Then in a File menu choose open File, Then go to the debug folder and choose the .exe file of the project,the screen would look like below. The Submenus defines the method, variables that are used within the program, to view the intermediate code of the function, just double click on it. This is the intermediate code for main function Hope it helps you in checking the intermediate code of the program, Post your valuable comments to admin@codespread.com or at my personal id...

Read More
Create a browser in C# WinForms
Mar09

Create a browser in C# WinForms

Hi Guys, This is Sathish, one of my friend was finding difficult in creating his own web browser, so I thought lets create a simple web browser in win forms of c# and share it with you. We are only going to use buttons, labels etc. in Win-forms and achieve our goal. Let’s start our recipe for the day. What is a web browser? In Simple words, it provides a way where you just have to provide the address and can view the contents of the web. Today I will show you how to create a simple web browser . First,let’s create a Menu bar in win-forms, so we can include any number of tabs when ever needed using Menu strip Option in toolbox. Then assign some functionality to it. It would look like this. private void nEWToolStripMenuItem_Click(object sender, EventArgs e) { Form1 fm = new Form1(); fm.Show(); } private void eXITToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } After creating a menu strip in the background, where I have added two menu items New and Exit, New for creating a new browser window, And, Exit for exiting the browser. We will add few more items like we have to create a address bar using ComboBox,Go button,Back,Forward and web browser to the window. Note: I am Using Combo box over here, it is required to alter the collections of combo box to the specified Url,you can also try with Textbox also. So let’s start coding for web browser in Search Button. here I am just navigating to the url specified in the combo box. Search Button : private void SEARCH_Click(object sender, EventArgs e) { webBrowser1.Navigate(new Uri(comboBox1.SelectedItem.ToString())) ; } Here make sure combo box values is converted to string. Back Button : private void BACK_Click(object sender, EventArgs e) { webBrowser1.GoBack(); } Forward Button : private void FORWARD_Click(object sender, EventArgs e) { webBrowser1.GoForward(); } It will look somewhat Like this on Completion. Now let’s run the programming, It will look like this. It’s Simple right; you can download the source code from https://www.box.com/files/0/f/723677963/1/f_6786628265. Please write your valuable queries over here or send it to admin@codespread.com,sSo that I can improve and add more value to my...

Read More
My first experience with LISTS in C#
Mar07

My first experience with LISTS in C#

Hi guys, this is Sathish, Lets discuss the concepts of lists. These are the concepts which I have planned to discuss with you guys today. What is a List and how it is advantageous than array list Creation of the list. Different methods in list. What is a list? A List is a collection of items that can be accessed by index.Lists can re-size dynamically where as Arrays have a limited size which is declared when they are initialized. List, as an advantage,do not need to be declared or managed during initialization. List class always resides in System.Collections.Generic namespace. Creation of List : The List class constructor takes a key data type. The data type can be any .NET data type. Consider these example for creating a list as integer,double and string respectively. ListListDemo = new List(); ListListDemo = new List(); ListListDemo = new List(); These is how we can create a List. Just a reminder, In case of key,You need to replace the datatype which your going to use. List provides different methods like: Add,remove,clear,contains,capacity,count distinct,max,min,sort,reverse insert and many other methods are there. Lets discuss about this in today’s topic. Adding Elements to the list. ListListDemo = new List(); ListDemo.Add("sathish"); ListDemo.Add("Kumar"); ListDemo.Add("sathish"); ListDemo.Add("Kumar"); foreach (string lines in ListDemo) { Console.WriteLine(lines); } Console.ReadKey(true); In the above example I have added 2 elements to a list having string data type. Remove Elements in list : ListListDemo = new List(); ListDemo.Add("Sathish"); ListDemo.Add("Kumar"); ListDemo.Add("Mahesh"); ListDemo.Remove("Kumar"); foreach (string lines in ListDemo) { Console.WriteLine(lines); } Console.ReadKey(true); In the above example, it searches the string list and remove the element according to key specified. Sorting Elements in the list. Sometimes it is required to sort the list in ascending or descending order.List provides one more method called sort(),where you can sort the list. List<string> ListDemo = new List<string>(); ListDemo.Add("Sathish"); ListDemo.Add("Kumar"); ListDemo.Add("Mahesh"); ListDemo.Remove("Kumar"); foreach (string lines in ListDemo) { Console.WriteLine(lines); } Console.ReadKey(true); Inserting an element to a list at specified position. Where it inserts the string to the 4th position. List<string> ListDemo = new List<string>(); ListDemo.Add("Sathish"); ListDemo.Add("Kumar"); ListDemo.Add("Mahesh"); ListDemo.Insert(3, "Kumar"); foreach (string lines in ListDemo) { Console.WriteLine(lines); } Console.ReadKey(true); Finding the  element in the list : List<string> ListDemo = new List<string>(); ListDemo.Add("Sathish"); ListDemo.Add("Kumar"); ListDemo.Add("Mahesh"); ListDemo.Insert(3, "Kumar"); if (ListDemo.Contains("Sathish")) { Console.WriteLine("The Elemets already Contains in the list"); } else { Console.WriteLine("The Elements is not there in the list"); } This is how we can determine whether list contains any duplication in a list. Removing the Duplication elements in the list : List Provides one more method called as distinct that removes the duplicated elements directly. List<string> ListDemo = new List<string>(); ListDemo.Add("Sathish"); ListDemo.Add("Kumar"); ListDemo.Add("Mahesh"); ListDemo.Insert(3, "Kumar"); List Chck...

Read More
Why Multiple Inheritance is discouraged?
Dec27

Why Multiple Inheritance is discouraged?

Hi Guys, This is Sathish Again,Today we will discuss why most of the higher languages eliminates Multiple Inheritance? Most of you guys already know that multiple inheritance is not available for development but what you might not know is the reason as why it is not possible. First of all,we will revisit few basics of inheritance. What is Inheritance? Wikipedia says “In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both, depending upon programming language support.” In simple words, Inheritance forces reusability where a class reuses the functionality of another class by inheriting all its traits.We can take an example to understand more: In real life, We inherit some of our behavior from our parents,so we can deduce our parents as Base class,and ourselves as Derived class. What are the types of Inheritance? Single Level Inheritance: It is the basic type of Inheritance where child class B inherits/extends the behavior of a base class A. For ex: We can have a child class like TV which extends base class like Electronics. Multi Level Inheritance: Here, Single inheritance is captured at different levels and called as multi-level inheritance. We have a derived class C which extends class B, which is a child class of base class A. For ex: Can we say Ipad extends Laptop and Laptop extends Desktop? Multiple Inheritance: The concept of multiple inheritance is a derived class C extends more than one base class like class A and Class B. Multiple inheritance is not supported by many languages and can be achieved by using interfaces. For ex: Child extends behavior of Father and Mother. Now we will move to our basic question, Consider the c++ program mentioned below , where I have created 3 classes,Two of them are base class and third one is the derived class, Base1 and Base2 are Base classes Derive is the Derived class /*Program about multiple inheritance */ class Base1 { public : void Display() { cout<<"We are in Base class1 " ; } } ; class Base2 { public : void Display() { cout<<"We are in Base class2 " ; } } ; class Derive :public Base1,public Base2 { } ; If we focus on Base1 and Base2, then it is clearly visible that, Base1 class has a method called Display Base2 class also has a method called Display, We extend these base classes with our derived class. Let’s move forward and create an instance of derived class, int main () { Derive d; d.Display(); return 0 ; } When we call the Display method,then the...

Read More
How to make a Connection between c# and mysql?
Dec25

How to make a Connection between c# and mysql?

This is my first article on codespread.com, titled ‘Connection between c# and mysql’.Before going into details, we should know that mysql is a open source software for data base management system. We use Microsoft visual c# and sql data source quite often , But in this tutorial I will show how we can connect mysql database and c# windows application. Screen 1 : We have created a demo application. Inside it,we place a Button. Where on the button click , we can create a table to the specified mysql database. Screen2 : We have created a table in mysql database. Next, In c# class file, import these namespaces. using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using MySql.Data.MySqlClient ; Where the above namespace “MySql.Data.MySqlClient” is the dll file ,in which all the connection commands will be residing .This can be found in mysql connector to c#/.net.Once you have imported the dll, you need to add this reference to your current project. namespace DemoApplication { /// <summary> /// Description of MainForm. /// </summary> public partial class MainForm : Form { public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } /* here What I have done is on button click, I have inserted a set of commands that creates a table in mysql database */ public void Button1Click(object sender, EventArgs e) { string quer= "SERVER=localhost; " + "DATABASE=sathish;" + "USERID=root;" + "PASSWORD=root;" ; /*The above command is used to connecting the mysql with c# , Where you need to select appropriate database ,userid and password */ MySqlConnection con = new MySqlConnection(quer); con.Open() ; /* You can use mysqlcommand or command builder for running the querries */ MySqlCommand cmd=new MySqlCommand(); try { /*Specifcation of the mysql connection over here */ cmd.Connection=con ; /*Command text is where we need to insert our queries */ cmd.CommandText="create table Demo(userid varchar(20),Password varchar(20));" ; /*Lastly, we need to execute the queries using ExecuteNonQuery of Mysqlcommand */ cmd.ExecuteNonQuery(); } catch(MySqlException ex) { label1.Text = ex.Message; } } } } Note: I prefer to build Mysqlconnection with an exception block so it would be easier diagnosing the error. You can download mysql connector and mysql to your system from www.Mysql.com . Next I’ll come with how you can insert,update and select operations using DataGrid.I hope, I was able to help you.For any queries, please comment over here or send your queries or articles to...

Read More