C# .Net Basic (Tutorial)


Looping in C#

Source Code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

// Intro to C#.net
// C# Basic
// Comment 1 Line
/*
Comment 1 Paraghrap (Multiple Line)
*/

namespace Basic_CSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnWhile_Click(object sender, EventArgs e)
{
int tempValue = 0;
lblWhile.Text = “”;
while (tempValue < 10)
{
lblWhile.Text = lblWhile.Text + “Loop Value: ” + tempValue + “\n”;
tempValue++; // increment value
}
}

private void btnDoWhile_Click(object sender, EventArgs e)
{
int n = 1;
int y = 1;
int hn;
int hy;
lblDoWhile.Text = “Result hn” + “\n”;
lblDoWhilePre.Text = “Result hy” + “\n”;
do
{
hy = ++y; // Prefix. y is incremented before its value is assigned to hy
hn = n++; // Postfix. n is incremented after its value is assigned to hn
lblDoWhile.Text = lblDoWhile.Text + “Value Do While ” + hn + “\n”;
lblDoWhilePre.Text = lblDoWhilePre.Text + “Value Pre ” + hy + “\n”;

} while (n <=10 );
}

private void btnFOR_Click(object sender, EventArgs e)
{
lblFOR.Text = “”;
for (int i = 0; i < 10; i++)
{
if (i % 2 == 0) //devide % (Sisa bagi)
{
lblFOR.Text = lblFOR.Text + “Loop Value: ” + i + “\n”;
}
}
}

private void btnForEach_Click(object sender, EventArgs e)
{
ArrayList arrList = new ArrayList();
arrList.Add(“Saufi”);
arrList.Add(“Pasaribu”);
arrList.Add(“Al Kahfi”);
arrList.Add(“Blog”);
arrList.Add(“C# Basic Sample”);

lblForEach.Text = “”;
foreach (string arr in arrList)
{
lblForEach.Text = lblForEach.Text + arr + “\n”;
}
}
}
}

About alkahfi

Bekerja di bidang IT-MIS di sebuah perusahaan Optik di Medan, sebagai Software Enginer.

Posted on August 23, 2008, in Life Style, Programming and tagged , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: