درس دهم - بخش دوم
ﻣﺜﺎل : ﻳﻚ ﺑﺮﻧﺎﻣـﻪ ی ﺳـﻲ ﺷـﺎرپ ﺟﺪﻳـﺪ console را در VS.NETﺑـﺎز ﻛﻨﯿـﺪ و ﻧـﺎم آﻧـﺮا دراﺑﺘـﺪا ex۱۹اﻧﺘﺨـﺎب ﻧﻤﺎﻳﯿـﺪ.
ﺳﭙﺲ ﻛﺪ زﻳﺮ را درون آن ﺑﻨﻮﻳﺴﯿﺪ :
ﺳﭙﺲ ﻛﺪ زﻳﺮ را درون آن ﺑﻨﻮﻳﺴﯿﺪ :
;using System
namespace ex۱۹
}
class Class۱
{
[STAThread]
static void Main(string[] args)
{
const int rows = ۴;
const int columns = ۳;
// declare a ۴x۳ integer array
int[,] rectangularArray = new int[rows, columns];
// populate the array
for (int i = ۰;i < rows;i++)
{
for (int j = ۰;j{
rectangularArray[i,j] = i+j;
}
}
// report the contents of the array
for (int i = ۰;i < rows;i++)
{
for (int j = ۰;j{
Console.WriteLine("rectangularArray[{۰},{۱}] = {۲}",
i,j,rectangularArray[i,j]);
}
}
Console.ReadLine();
}
}
}
namespace ex۱۹
}
class Class۱
{
[STAThread]
static void Main(string[] args)
{
const int rows = ۴;
const int columns = ۳;
// declare a ۴x۳ integer array
int[,] rectangularArray = new int[rows, columns];
// populate the array
for (int i = ۰;i < rows;i++)
{
for (int j = ۰;j
rectangularArray[i,j] = i+j;
}
}
// report the contents of the array
for (int i = ۰;i < rows;i++)
{
for (int j = ۰;j
Console.WriteLine("rectangularArray[{۰},{۱}] = {۲}",
i,j,rectangularArray[i,j]);
}
}
Console.ReadLine();
}
}
}
: ﺗﻮﺿﯿﺤﺎﺗﻲ در ﻣﻮرد ﻛﺪ ﻓﻮق
١- ﻧﺤﻮه ی ﺗﻌﺮﻳﻒ ، ﻣﻘﺪار دھﻲ اوﻟﯿﻪ و اﺳﺘﻔﺎده از آراﻳﻪ ھﺎی دو ﺑﻌﺪی را در ﻣﺜﺎل ﻓﻮق ﻣﻼﺣﻈﻪ ﻣﻲ ﻧﻤﺎﻳﯿﺪ.
٢- در ﻳﻚ آراﻳﻪ ی دوﺑﻌﺪی ﻣﺤﻞ ﻗﺮار ﮔﯿﺮی ردﻳﻒ ھﺎ و ﺳﺘﻮن ھﺎ ﺑﺮای ﻣﺜﺎل ﺑﻪ ﺻﻮرت زﻳﺮ اﺳﺖ :
new int[rows, columns]
: اﺳﺘﻔﺎده از آراﻳﻪ ھﺎی ﭼﻨﺪ ﺑﻌﺪی
. اﻧﺘﺨـﺎب ﻧﻤﺎﻳﯿـﺪex۲۰ ﺑـﺎز ﻛﻨﯿـﺪ و ﻧـﺎم آﻧـﺮا دراﺑﺘـﺪاVS.NET را در console ﻣﺜﺎل : ﻳﻚ ﺑﺮﻧﺎﻣـﻪ ی ﺳـﻲ ﺷـﺎرپ ﺟﺪﻳـﺪ
ﺳﭙﺲ ﻛﺪ زﻳﺮ را درون آن ﺑﻨﻮﻳﺴﯿﺪ :
ﺳﭙﺲ ﻛﺪ زﻳﺮ را درون آن ﺑﻨﻮﻳﺴﯿﺪ :
using System;
namespace ex۲۰
{
class Class۱
{
[STAThread]
static void Main( string[] args )
{
const int rows = ۴;
const int columns = ۳;
// imply a ۴x۳ array
int[,] rectangularArray =
{
{۰,۱,۲},
,{۵,۴,۳}
,{۸,۷,۶}
{۱۱,۰۱,۹}
;{
(++for (int i = ۰;i < rows;i
}
(++for (int j = ۰;j}
,"{۲} = [{۱},{۰}]Console.WriteLine("rectangularArray
;([i,j,rectangularArray[i,j
{
{
{
{
{
namespace ex۲۰
{
class Class۱
{
[STAThread]
static void Main( string[] args )
{
const int rows = ۴;
const int columns = ۳;
// imply a ۴x۳ array
int[,] rectangularArray =
{
{۰,۱,۲},
,{۵,۴,۳}
,{۸,۷,۶}
{۱۱,۰۱,۹}
;{
(++for (int i = ۰;i < rows;i
}
(++for (int j = ۰;j
,"{۲} = [{۱},{۰}]Console.WriteLine("rectangularArray
;([i,j,rectangularArray[i,j
{
{
{
{
{
ﺗﻮﺿﯿﺤﺎﺗﻲ در ﻣﻮرد ﻛﺪ ﻓﻮق :
١- در ﺣﻘﯿﻘﺖ ﻣﺜﺎل ﻓﻮق ﺗﻌﺮﻳﻒ آراﻳﻪ اﻳﻲ از آراﻳﻪ ھﺎ ﺑﻮد.
٢- ﭼﻮن ﻣﻘﺪار دھﻲ اوﻟﯿﻪ ﺑﻪ ﺻﻮرت واﺿﺤﻲ اﻧﺠﺎم ﺷـﺪه ﻧﯿـﺎزی ﺑـﻪ ذﻛـﺮ اﺑﻌـﺎد آراﻳـﻪ ﺑـﻪ ﺻـﻮرت ﺻـﺤﯿﺢ وﺟـﻮد ﻧﺪاﺷﺖ
١- در ﺣﻘﯿﻘﺖ ﻣﺜﺎل ﻓﻮق ﺗﻌﺮﻳﻒ آراﻳﻪ اﻳﻲ از آراﻳﻪ ھﺎ ﺑﻮد.
٢- ﭼﻮن ﻣﻘﺪار دھﻲ اوﻟﯿﻪ ﺑﻪ ﺻﻮرت واﺿﺤﻲ اﻧﺠﺎم ﺷـﺪه ﻧﯿـﺎزی ﺑـﻪ ذﻛـﺮ اﺑﻌـﺎد آراﻳـﻪ ﺑـﻪ ﺻـﻮرت ﺻـﺤﯿﺢ وﺟـﻮد ﻧﺪاﺷﺖ
+ نوشته شده در چهارشنبه دوازدهم بهمن ۱۳۹۰ ساعت 1:11 توسط محسن زاده
|