C# Programming Flashcards
22 Questions
100 Views

C# Programming Flashcards

Created by
@ColorfulTaylor

Questions and Answers

What are the parts of a C# program structure?

Namespace declaration, a class, class methods, class attributes, a Main method, statements and expressions, comments.

What is the use of the 'new' keyword in C#?

It is used to create objects and invoke constructors, as well as create instances of anonymous types.

What does the 'sealed' keyword do in C#?

It prevents other classes from inheriting from a sealed class and can also be used on methods to prevent overriding.

What does the 'this' keyword refer to in C#?

<p>It refers to the current instance of the class.</p> Signup and view all the answers

What does the 'static' keyword signify?

<p>It declares a static member that belongs to the type itself rather than a specific object.</p> Signup and view all the answers

How do you create a string object in C#?

<p>By assigning a string literal to a String variable, using a String class constructor, or using the string concatenation operator.</p> Signup and view all the answers

What properties are available in the String class?

<p>Chars and Length.</p> Signup and view all the answers

What is the purpose of a namespace in C#?

<p>To keep one set of names separate from another.</p> Signup and view all the answers

What are exception handling keywords in C#?

<p>try, catch, finally, and throw.</p> Signup and view all the answers

What does the 'try' keyword do?

<p>It identifies a block of code where exceptions may occur.</p> Signup and view all the answers

What does the 'catch' keyword indicate?

<p>It indicates that an exception is being handled.</p> Signup and view all the answers

What is the function of the 'finally' keyword?

<p>To execute a block of code regardless of whether an exception was thrown.</p> Signup and view all the answers

What is the use of the 'throw' keyword?

<p>To throw an exception when a problem occurs.</p> Signup and view all the answers

What is an abstract class in C#?

<p>A class that cannot be instantiated and provides a common definition for derived classes.</p> Signup and view all the answers

What is an interface in C#?

<p>A syntactical contract that defines members that classes must implement.</p> Signup and view all the answers

What is the purpose of arrays in C#?

<p>To store a fixed-size sequential collection of elements of the same type.</p> Signup and view all the answers

What does declaring an array look like in C#?

<p>Using a datatype followed by [] and the array name.</p> Signup and view all the answers

How are values assigned to array elements in C#?

<p>Using the index number or during the declaration.</p> Signup and view all the answers

What is the purpose of collection classes in C#?

<p>To provide specialized classes for data storage and retrieval.</p> Signup and view all the answers

What is a Hashtable in C#?

<p>A collection of key-and-value pairs organized by hash code.</p> Signup and view all the answers

What is the definition of a Stack in C#?

<p>A last-in, first-out collection of objects.</p> Signup and view all the answers

What is a Queue in C#?

<p>A first-in, first-out collection of objects.</p> Signup and view all the answers

Study Notes

Program Structure

  • A C# program includes a namespace declaration, a class, class methods, class attributes, a Main method, statements and expressions, and comments.

"new" Keyword

  • The "new" keyword is utilized to create objects, invoke constructors, and create instances of anonymous types.
  • It invokes the default constructor for value types.

"sealed" Keyword

  • The "sealed" modifier prevents other classes from inheriting from a sealed class.
  • Can be applied to methods or properties to prevent overriding of virtual methods in derived classes.

"this" Keyword

  • Refers to the current instance of the class and modifies the first parameter of an extension method.

"static" Keyword

  • Declares static members that belong to the type itself, not to instances.
  • Applicable to classes, fields, methods, properties, operators, events, and constructors (not indexers or finalizers).

Strings

  • Strings are essentially arrays of characters but commonly declared using the string keyword, an alias for System.String.

Creating a String Object

  • Can be created by assigning a string literal, using a String class constructor, concatenating strings, invoking a method that returns a string, or formatting a value/object to convert to a string.

Properties of the String Class

  • Chars: Accesses the Char object at a specified position.
  • Length: Returns the number of characters in the string.

Namespace

  • Provides a way to separate sets of names to avoid conflicts between classes with identical names.

Using Keyword

  • Indicates that the program utilizes names from the specified namespace.

"abstract" Keyword

  • Creates incomplete classes or members that must be implemented in derived classes.

Abstract Classes

  • Cannot be instantiated and define a common base for multiple derived classes.
  • May declare abstract methods that derived classes must implement.

Virtual Method

  • Facilitates overriding base class implementations in derived classes for consistent functionality across object sets.

Declaring Interfaces

  • Interfaces are declared with the interface keyword and are public by default.

Interface

  • Represents a contract that classes must follow, defining 'what' should be implemented, leaving 'how' to the derived classes.
  • Contains member declarations without implementations.

Exception

  • Represents problems during program execution, such as attempts to divide by zero.

Exception Handling Keywords

  • Key terms include try, catch, finally, and throw.

try

  • Identifies a block of code where exceptions may occur, followed by catch blocks for handling.

catch

  • Handles specific exceptions where they occur, indicated by the catch keyword.

finally

  • Executes a set of statements regardless of whether an exception was thrown, ensuring critical operations are completed.

throw

  • Used to initiate an exception when an issue arises in the program.

Exception Classes

  • C# exceptions are represented by classes derived from System.Exception.
  • Includes System.ApplicationException and System.SystemException for application and predefined exceptions, respectively.

Handling Exceptions

  • C# employs try and catch blocks for structured exception handling, separating core statements from error-handling.

Throwing Objects

  • Objects derived from System.Exception can be thrown in a catch block using the throw statement.

Arrays in C#

  • An array is a fixed-size collection of same-type elements, stored in contiguous memory locations, accessed via indices.

Declaring Arrays

  • Declared using a datatype followed by [] to specify its rank (size) and name.

Initializing Arrays

  • Arrays require the new keyword for instantiation, and are initialized to assign values.

Assigning Values to an Array

  • Values can be assigned by index after declaration or during declaration with an initializer list.

Collections in C#

  • Specialized classes for data storage and retrieval, supporting stacks, queues, and lists.
  • Collection classes allow dynamic memory allocation and indexed access.

Classes of the System.Collection Namespace

  • Key classes include ArrayList, HashTable, Stack, and Queue.

ArrayList

  • An ordered, indexable collection that allows adding and removing items dynamically with automatic resizing.

HashTable

  • Collection of key-value pairs, organized via hash codes for quick access based on keys.

Stack

  • Represents a last-in, first-out (LIFO) collection, where adding items is "pushing" and removal is "popping".

Queue

  • Represents a first-in, first-out (FIFO) collection, where adding is "enqueue" and removal is "deque".

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your knowledge of C# programming concepts with these flashcards. Each card covers essential terminology and definitions that are key to understanding C#. Use these flashcards for quick revision or for learning new terms.

More Quizzes Like This

C++ Programming Concepts
55 questions
Python Programming Concepts
10 questions

Python Programming Concepts

ViewableCombination avatar
ViewableCombination
Java Programming Concepts
29 questions
Use Quizgecko on...
Browser
Browser