C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Compiling C# Files


Posted Date: 15 Aug 2008    Resource Type: Articles    Category: General

Posted By: Gaurav Arora       Member Level: Gold
Rating:     Points: 10



There are certain options by which you can compile files with different types like class library .dll or executable files .exe etc.


< tr>
< td nowrap="" width="73">
< p align="center">
< strong>Option< /strong>< /p>
< /td>
< td nowrap="" width="360">
< p align="center">
< strong>Description< /strong>< /p>
< /td>
< /tr>
< tr>
< td nowrap="" width="73">
< p>
/t :exe< /p>
< /td>
< td nowrap="" width="360">
< p>
Produces a Console Application, which is the default option< /p>
< /td>
< /tr>
< tr>
< td nowrap="" width="73">
< p>
/t :library< /p>
< /td>
< td nowrap="" width="360">
< p>
Produces a Class Library with its Manifest< /p>
< /td>
< /tr>
< tr>
< td nowrap="" width="73">
< p>
/t :module< /p>
< /td>
< td nowrap="" width="360">
< p>
Produces a component but without manifest< /p>
< /td>
< /tr>
< tr>
< td nowrap="" width="73">
< p>
/t :winexe< /p>
< /td>
< td nowrap="" width="360">
< p>
Produces a Windows application [not a console window]< /p>
< /td>
< /tr>
< /table>


The above list is very short and at this time its enough to display here, all other features will discuss in next couple of chapter(s).

How can Console Application call Class Library file?


With the help of switch option(s) you can do this. /t :library will generate the class library with its manifest and this will call at runtime. With the use of /r switch you can call the other class library file to any console application.

Let's check the following example: See Code-Calling Library Class.

/* This Example is a part of different 
* examples shown in Book:
* C#2005 Beginners: A Step Ahead
* Written by: Gaurav Arora
* Reach at : gaurav.aroraose@yahoo.co.in*/

// File name : mathclass.cs

namespace CSharp.AStepAhead.mathclass
{

public class mathclass
{
//Signature of class
public int multiply(int num1, int num2)
{
return num1 * num2;
}
public int add(int num1, int num2)
{
return num1 + num2;
}
public int substract(int num1, int num2)
{
return num1 - num2;
}
public int divide(int num1, int num2)
{
return num1 / num2;
}
public int square(int num1)
{
return num1 * num1;
}
}
}

/* This Example is a part of different 
* examples shown in Book:
* C#2005 Beginners: A Step Ahead
* Written by: Gaurav Arora
* Reach at : gaurav.aroraose@yahoo.co.in*/
// File name : mathclassclient.cs
using System;
namespace CSharp.AStepAhead.mathclass
{

public class mathclassclient
{
public static void Main()
{
int opt=0;
//Create an object of mathclass
mathclass myClass = new mathclass();
while (opt != 6)
{
Console.WriteLine("This uses mathclass\n");
Console.WriteLine("Enter your choice[1-6] - 1:Addition 2: Substraction 3: Multiplication 4: Division 5: Square 6: Exit");
opt = int.Parse(Console.ReadLine());

if (opt == 1)
{
Console.WriteLine("Enter first number:");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second number:");
int num2 = int.Parse(Console.ReadLine());

Console.WriteLine("Addition of {0} and {1} = {2}", num1, num2, myClass.add(num1, num2));


}

else if (opt == 2)
{
Console.WriteLine("Enter first number:");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second number:");
int num2 = int.Parse(Console.ReadLine());

Console.WriteLine("Substraction of {0} and {1} = {2}", num1, num2, myClass.substract(num1, num2));

}
else if (opt == 3)
{
Console.WriteLine("Enter first number:");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second number:");
int num2 = int.Parse(Console.ReadLine());

Console.WriteLine("Multiplication of {0} and {1} = {2}", num1, num2, myClass.multiply(num1, num2));

}
else if (opt == 4)
{
Console.WriteLine("Enter first number:");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second number:");
int num2 = int.Parse(Console.ReadLine());

Console.WriteLine("Division of {0} and {1} = {2}", num1, num2, myClass.divide(num1, num2));

}

else if (opt == 5)
{
Console.WriteLine("Enter number:");
int num = int.Parse(Console.ReadLine());

Console.WriteLine("Square of {0} = {1}", num, myClass.square(num));


}

Console.ReadLine();
Console.Clear();
}
if (opt == 6)
{
Console.WriteLine("This example Showed, how to use class file?");
Console.ReadLine();

}

}
}

}



Now, compile above file into .NET dll file as follows:

csc /t:library mathclass.cs


Compile the above file as follows:
csc mathclass.cs /r:mathclass.dll


Formatting output(s) and Using Comments


The following table tells how you can format the output of your program through Console application See Table - Console Option(s).

C#:Console Options and Formatting output(s)


<p>The following tables described the how can you format your console application using console options: </p>
</div>
<div>
Console Options
< table border="1" cellspacing="0" cellpadding="0" width="675">
< tr>
< td width="219"> < p align="center"> < strong> Name< /strong> < /p> < /td>
< td width="456"> < p align="center"> < strong> Description< /strong> < /p> < /td>
< /tr>
< tr>
< td width="219"> < p> Read< /p> < /td>
< td width="456"> < p> Reads the character entered by the user< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> ReadLine< /p> < /td>
< td width="456"> < p> Reads the character entered by the user but adds the new line character at the end< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> ReadKey, ReadKey(bool intercepts)< /p> < /td>
< td width="456"> < p> Read the function keys pressed by the user, true (default option) to show the keys on screen otherwise false< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> BackgroundColors< /p> < /td>
< td width="456"> < p> Gets or sets the background color of console< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> ForegroundColor< /p> < /td>
< td width="456"> < p> Gets or sets the foreground color of console< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> ReSetColors< /p> < /td>
< td width="456"> < p> Set the Foreground and Background Console Windows Color to their default< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> BufferHeight< /p> < /td>
< td width="456"> < p> Gets or Sets the height of buffer area< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> BufferWidth< /p> < /td>
< td width="456"> < p> Gets or Sets the width of buffer area< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> SetBufferSize(int width, int height)< /p> < /td>
< td width="456"> < p> Set the height and Width of the screen buffer are.< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> SetCursorPosition(int left, int right)< /p> < /td>
< td width="456"> < p> Sets the cursor position< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> Write< /p> < /td>
< td width="456"> < p> Write the output to the console window< /p> < /td>
< /tr>
< tr>
< td width="219"> < p> WriteLine< /p> < /td>
< td width="456"> < p> Write the output to the console window and adds the newline character at end< /p> < /td>
< /tr>
< /table>
< /div>
< div class="content">
< b> < u> Format output(s)< /u> < /b>
< table border="1" cellspacing="0" cellpadding="0" width="311">
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> < strong> String< /strong> < /p> < /td>
< td width="247" nowrap="nowrap"> < p align="center"> < strong> Descrption< /strong> < /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> C< /p> < /td>
< td width="247"> < p> Output to local currency< /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> D< /p> < /td>
< td width="247"> < p> Output to Decimal< /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> E< /p> < /td>
< td width="247"> < p> Output to Scientific notations< /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> F< /p> < /td>
< td width="247"> < p> Output to fixed point format< /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> G< /p> < /td>
< td width="247"> < p> Output to Genera format< /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> N< /p> < /td>
< td width="247"> < p> Output to number format, thousand separator with commas(,)< /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> P< /p> < /td>
< td width="247"> < p> Output to %age format< /p> < /td>
< /tr>
< tr>
< td width="64" nowrap="nowrap"> < p align="center"> X< /p> < /td>
< td width="247"> < p> Output to Hexadecimal format< /p> < /td>
< /tr>
< /table>
< /div>



Comments


Comments are the lines which are not compiled but useful for programer's reference. C# uses two type of comments just like in C++
Single line Comment: 
Eg. //This is single line comment

Multi-line of group comment
Eg. /* This is first line
* This is second line */


For more details, visit http://www.msdotnetheaven.com/ChaptersCsharp/csharplanguagei.htm




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Interviews  .  C# Syntax  .  Article  .  .net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: The Main() Method
Previous Resource: C# files : XML Documentation
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

email fax service

Contact Us    Privacy Policy    Terms Of Use