28 Mart 2009 Cumartesi
23 Mart 2009 Pazartesi
foreach ifadesi
using System;
using System.Collections;
class Test
{
static void WriteList(ArrayList list) {
foreach (object o in list)
Console.WriteLine(o);
}
static void Main() {
ArrayList list = new ArrayList();
for (int i = 0; i < 10; i++)
list.Add(i);
WriteList(list);
}
}
using System.Collections;
class Test
{
static void WriteList(ArrayList list) {
foreach (object o in list)
Console.WriteLine(o);
}
static void Main() {
ArrayList list = new ArrayList();
for (int i = 0; i < 10; i++)
list.Add(i);
WriteList(list);
}
}
for ifadesi
using System;
class Test
{
static void Main() {
for (int i = 0; i < 10; i++)
Console.WriteLine(i);
}
}
class Test
{
static void Main() {
for (int i = 0; i < 10; i++)
Console.WriteLine(i);
}
}
do ifadesi
using System;
class Test
{
static void Main() {
string s;
do {
s = Console.ReadLine();
}
while (s != "Exit");
}
}
class Test
{
static void Main() {
string s;
do {
s = Console.ReadLine();
}
while (s != "Exit");
}
}
while ifadesi
using System;
class Test
{
static int Find(int value, int[] arr) {
int i = 0;
while (arr[i] != value) {
if (++i > arr.Length)
throw new ArgumentException();
}
return i;
}
static void Main() {
Console.WriteLine(Find(3, new int[] {5, 4, 3, 2, 1}));
}
}
class Test
{
static int Find(int value, int[] arr) {
int i = 0;
while (arr[i] != value) {
if (++i > arr.Length)
throw new ArgumentException();
}
return i;
}
static void Main() {
Console.WriteLine(Find(3, new int[] {5, 4, 3, 2, 1}));
}
}
switch ifadesi
using System;
class Test
{
static void Main(string[] args) {
switch (args.Length) {
case 0:
Console.WriteLine("No arguments were provided");
break;
case 1:
Console.WriteLine("One arguments was provided");
break;
default:
Console.WriteLine("{0} arguments were provided");
break;
}
}
}
class Test
{
static void Main(string[] args) {
switch (args.Length) {
case 0:
Console.WriteLine("No arguments were provided");
break;
case 1:
Console.WriteLine("One arguments was provided");
break;
default:
Console.WriteLine("{0} arguments were provided");
break;
}
}
}
if ifadesi
The if statement
An if statement selects a statement for execution based on the value of a Boolean expression. An if statement may optionally include an else clause that executes if the Boolean expression is false.
The example
using System;
12 Copyright ? Microsoft Corporation 1999-2000. All Rights Reserved.
class Test
{
static void Main(string[] args) {
if (args.Length == 0)
Console.WriteLine("No arguments were provided");
else
Console.WriteLine("Arguments were provided");
}
}
An if statement selects a statement for execution based on the value of a Boolean expression. An if statement may optionally include an else clause that executes if the Boolean expression is false.
The example
using System;
12 Copyright ? Microsoft Corporation 1999-2000. All Rights Reserved.
class Test
{
static void Main(string[] args) {
if (args.Length == 0)
Console.WriteLine("No arguments were provided");
else
Console.WriteLine("Arguments were provided");
}
}
Kaydol:
Kayıtlar (Atom)