Chapter 14: Arrays

Cards (30)

  • What is an array in programming?
    A continuous block of memory for elements
  • Why are arrays considered a transportable datatype?
    They can be passed between different programming languages
  • What is the typical dimensionality of arrays?
    Most arrays are one dimensional
  • How can multi-dimensional arrays be useful in game development?
    They can represent 2D tile layouts effectively
  • What does the dimension of an array refer to?
    The number of indices to find an element
  • What is the significance of the array type definition?
    It specifies the element type and uses []
  • Can the length of an array change after creation?
    No, the length is fixed after creation
  • How can the length of an array be retrieved?
    Using the length field
  • What notation is used to specify positions in an array?
    Indexer notation with []
  • How can arrays be initialized in C#?
    Using initialization syntax or collection expression syntax
  • What is the formal parameter definition for array arguments?
    It cannot specify the expected length of the array
  • How can the length of an array argument be found?
    Using the Length property
  • What does the String.Split function return?
    A one dimensional array of strings
  • What happens when a program starts in C#?
    The static void Main method is called
  • How are command arguments passed to a program?
    As an array of strings
  • What is the structure of a multi-dimensional array?
    It requires multiple indices to identify elements
  • How is the type definition of a multi-dimensional array structured?
    It uses commas to separate index positions
  • How is the number of elements in a two-dimensional array calculated?
    By multiplying the lengths of both dimensions
  • What is a key difference between multi-dimensional arrays and jagged arrays?
    Jagged arrays can have sub-arrays of different lengths
  • What is the purpose of the params keyword in C#?
    To allow variable number of arguments in a method
  • What does the Array class in .NET provide?
    Utility methods for array manipulation
  • What can the Array class do with arrays?
    Copy, search, clone, and resize arrays
  • What is the result of resizing an array in .NET?
    A new array is allocated with copied items
  • What is the notation for collection initializers?
    Curly braces {}
  • What is the purpose of the spread element in collections?
    To flatten a list of lists into a single list
  • What are the key features of single-dimensional arrays?
    • Reference type
    • Fixed length after creation
    • Length can be retrieved using Length property
    • Supports foreach iterations
    • Can be initialized using different syntaxes
  • What are the characteristics of multi-dimensional arrays?
    • Requires multiple indices for access
    • Defined with commas in type definition
    • Length is the product of dimensions
    • Can be iterated using foreach
  • What are the advantages of jagged arrays?
    • Allows sub-arrays of different lengths
    • Reduces memory usage for varying lengths
    • Individual items can be accessed and modified
  • What are the utility methods provided by the Array class?
    • Copying arrays
    • Searching for elements
    • Cloning arrays (shallow copy)
    • Resizing arrays (new allocation)
  • What are the differences between collection initializers and collection expressions?
    • Collection initializers use curly braces {}
    • Collection expressions use square brackets []
    • Both are considered equivalent in this context