Lecture overview -- Keyboard shortcut: 'u'  Previous page: Non-simple types -- Keyboard shortcut: 'p'  Next page: Pointers and references -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 10 : 43
Object-oriented Programming in C#
Introduction to C#
Arrays and Strings

Both arrays and strings are classical types, supported by almost any programming language. Both arrays and strings are reference types. It means that arrays and strings are accessed via references.

Both arrays and strings are dealt with as objects in C#

In addition, there is special notation in the C# language of arrays and strings

  • Similarities

    • C# and C have similar syntaxes for arrays and strings

  • Differences

    • Arrays in C# can be rectangular or jagged (arrays of arrays)

    • In C#, an array is not a pointer to the first element

    • Index out of bound checking is done in C#

    • Strings are immutable in C#, but not in C

    • In C# there are two kinds of string literals: "a string\n" and @"a string\n"

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/array-string-types/ex-array.csDemonstrations of array types in C#. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/array-string-types/array-outputOutput from the array demonstration program.


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/array-string-types/ex-string.csA demonstration of strings in C#. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/array-string-types/string-outputOutput from the string demonstration program.


Go to exerciseUse of array types
Go to exerciseUse of string types
In C# it is often more attractive to use a (type parameterized) collection class instead of an array