
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is the difference between initialization and assignment of values in C#?
Let us understand the difference between initialization and assignment of values.
Declaring an array.
int [] n // declaring
Initialization
Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance of the array.
int n= new int[10]; // initialization
Let’s assign value. You can assign values to individual array elements, by using the index number −
n[0] = 100; n[1] = 200
With C#, you can declare, initialize and assign values to an array in a single line −
int n= new int[10] {100, 200, 300, 400, 500};
When you create an array, C# compiler implicitly initializes each array element to a default value depending on the array type. For example, for an int array all elements are initialized to 0.
- Related Articles
- What is the difference between = and: = assignment operators?
- Initialization, declaration and assignment terms in Java
- Is there a difference between copy initialization and direct initialization in C++?
- Explain the variable declaration, initialization and assignment in C language
- What's the difference between assignment operator and copy constructor in C++?
- Difference Between Copy Constructor and Assignment Operator in C++
- What is the meaning and usage of ‘=&’ assignment operator in PHP?
- What are the default initialization values of elements in an array using Java?
- What is the difference between $ and @ in R?
- What is the difference between == and === in JavaScript?
- What is Assignment Operator (=) in JavaScript?
- What is the difference between /* */ and /** */ comments in Java?
- What is the difference between NA and in R?
- What is the difference between | and || operators in c#?
- What is the difference between >> and >>> operators in Java?

Advertisements