explore micro structure
var number = new[] { 5.0, 6.5, 7.3 }; //! one style array
Console.WriteLine(number[0]);
int[] myary = new int[] { 5, 6, 7 }; //! second style array
Console.WriteLine(myary[1]);
int[] myary3 = { 5, 6, 7 }; //! third style array
Console.WriteLine(myary3[2]);
static void Main(string[] args) => add(50, 60);
static void add()
{
int a = 50, b = 60;
int result = a + b;
Console.WriteLine(value: result);
}
static void Main(string[] args) => Console.WriteLine(value: add(50, 60));
static int add(int a, int b)
{
var result = a + b;
return result;
}
static void Main(string[] args)
{
//pass by value
var studentGrade = 75;
Console.WriteLine("student grade before extra credit {0}", studentGrade);
giveExtracredit(studentGrade);
Console.WriteLine("student grade after extra credit {0}", studentGrade);
//pass by reference
int[] grade = new int[] { 10 };
Console.WriteLine("Student grade before extra credit {0}", grade[0]);
giveExtragrade(grade);
Console.WriteLine("Student grade after extra credit {0}", grade[0]);
//ref keyword use to create force to reference
int studentGrade2 = 75;
Console.WriteLine("Student grade before extra credit {0}", studentGrade2);
giveExtracredit2(ref studentGrade2);
Console.WriteLine("Student grade after exra credit {0}", studentGrade2);
//out keyword
int add;
int mult;
AddMult(5, 10, out add, out mult);
Console.WriteLine(add);
Console.WriteLine(mult);
}
public static void giveExtracredit(int studentGrade) => studentGrade += 3;
public static void giveExtragrade(int[] grade) => grade[0] += 3;
public static void giveExtracredit2(ref int studentGrade2) => studentGrade2 += 3;
public static void AddMult(int a, int b, out int add, out int mult)
{
add = a + b;
mult = a * b;
}
}