diff --git a/docs/csharp/programming-guide/arrays/single-dimensional-arrays.md b/docs/csharp/programming-guide/arrays/single-dimensional-arrays.md index 9418e4d9f2f7f..1fa6df27586e6 100644 --- a/docs/csharp/programming-guide/arrays/single-dimensional-arrays.md +++ b/docs/csharp/programming-guide/arrays/single-dimensional-arrays.md @@ -44,6 +44,12 @@ Consider the following array declaration: :::code language="csharp" source="snippets/SingleDimensionArrays.cs" id="FinalInstantiation"::: The result of this statement depends on whether `SomeType` is a value type or a reference type. If it's a value type, the statement creates an array of 10 elements, each of which has the type `SomeType`. If `SomeType` is a reference type, the statement creates an array of 10 elements, each of which is initialized to a null reference. In both instances, the elements are initialized to the default value for the element type. For more information about value types and reference types, see [Value types](../../language-reference/builtin-types/value-types.md) and [Reference types](../../language-reference/keywords/reference-types.md). + +## Retreving data from Array + +You can retrieve the data of an array by use an index. For example: + +:::code language="csharp" source="snippets/RetrevingArrayElements.cs" id="RetrevingDataArray" interactive="try-dotnet-method"::: ## See also diff --git a/docs/csharp/programming-guide/arrays/snippets/RetrevingArrayElements.cs b/docs/csharp/programming-guide/arrays/snippets/RetrevingArrayElements.cs new file mode 100644 index 0000000000000..ce0c012fb7385 --- /dev/null +++ b/docs/csharp/programming-guide/arrays/snippets/RetrevingArrayElements.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace arrays +{ + public class RetrevingArrayElements + { + public static void Examples() + { + Retreving(); + } + + private static void Retreving() + { + // + string[] weekDays2 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + + Console.WriteLine(weekDays2[0]); + Console.WriteLine(weekDays2[1]); + Console.WriteLine(weekDays2[2]); + Console.WriteLine(weekDays2[3]); + Console.WriteLine(weekDays2[4]); + Console.WriteLine(weekDays2[5]); + Console.WriteLine(weekDays2[6]); + + /*Output: + Sun + Mon + Tue + Wed + Thu + Fri + Sat + */ + // + } + } +}