Introduction to C# - slide 36 : 43 |
Option Strict On Option Explicit On Module ArrayDemo Sub Sum(ByVal table() As Integer, ByRef result as Integer) result = 0 For i as Integer = 0 To 9 result += table(i) Next End Sub Sub Main() Dim someNumbers(9) as Integer Dim theSum as Integer = 0 For i as Integer = 0 To 9 someNumbers(i) = i * i Next Sum(someNumbers, theSum) Console.WriteLine(theSum) End Sub End Module
using System; class ProcedureDemo{ public static void Sum(int[] table, ref int result){ result = 0; for(int i = 0; i <= 9; i++) result += table[i]; } public static void Main(){ int[] someNumbers = new int[10]; int theSum = 0; for(int i = 0; i <= 9;i++) someNumbers[i] = i * i; Sum(someNumbers, ref theSum); Console.WriteLine(theSum); } }
Option Strict On Option Explicit On Module ArrayDemo Function Sum(ByVal table() As Integer) as Integer Dim result as Integer = 0 For i as Integer = 0 To 9 result += table(i) Next return result End Function Sub Main() Dim someNumbers(9) as Integer Dim theSum as Integer = 0 For i as Integer = 0 To 9 someNumbers(i) = i * i Next theSum = Sum(someNumbers) Console.WriteLine(theSum) End Sub End Module
using System; class ProcedureDemo{ public static int Sum(int[] table){ int result = 0; for(int i = 0; i <= 9; i++) result += table[i]; return result; } public static void Main(){ int[] someNumbers = new int[10]; int theSum = 0; for(int i = 0; i <= 9;i++) someNumbers[i] = i * i; theSum= Sum(someNumbers); Console.WriteLine(theSum); } }