C# Lab01
C# Lab01
Programming in C#
Lab 1
Objectives:
At the end of this session, you will able to understand:
Data type in C#
Input and output data in C#
Number and datetime format specifier
using System;
class Example
{
static void Main(string[] args)
{
int intVal;
double dblVal;
string strVal;
intVal = 10;
dblVal = 3.142;
strVal = "Fpt Aptech";
Console.WriteLine("{0} is an integer value", intVal);
Console.WriteLine("{0} is an double value", dblVal);
Console.WriteLine("{0} is an string", strVal);
Console.ReadLine();
}
}
using System;
using System.Text;
class Example1
© 2009 FPT Aptech 4
C# - Lab 1 – Data Type, Input and Output, Conversion, format specifier
{
static void Main(string[] args)
{
int valueVal = 5;
Test(valueVal);
Console.WriteLine("The value of the variable is {0}", valueVal);
Console.ReadLine();
}
static void Test(int valueVal)
{
int temp = 5;
valueVal = temp * 2;
}
}
using System;
class ReferenceType
{
public int valueVal;
}
class TestReference
{
static void Main(string[] args)
{
ReferenceType refer = new ReferenceType();
© 2009 FPT Aptech 5
C# - Lab 1 – Data Type, Input and Output, Conversion, format specifier
refer.valueVal = 5;
Test(refer);
Console.WriteLine("The value of the variable is {0}",
refer.valueVal);
Console.ReadLine();
}
static void Test(ReferenceType refer)
{
int temp = 5;
refer.valueVal = temp * 2;
}
}
Exercise 4: output
Exercise 5: Input
using System;
/* The program demonstrates the input and output operations.*/
class Student
{
static void Main(string[] args)
{
//Declaring integer constant to store value 100
const int percentConst = 100;
//Declaring variable to store the student name
string studentName;
References
1) CD ROM C# Programming, Aptech Education
2) http://www.java2s.com/Tutorial/CSharp/CatalogCSharp.htm
3) MSDN Document