Header Ads

hence you have to define data type for variables


Data Types in a programming language describes that what type of data a variable can hold . C# is a strongly typed language, hence you have to define data type for variables. you cannot use variable without data types.
When we declare a variable, we have to tell the compiler about what type of the data the variable can hold or which data type the variable belongs to.
  Syntax   : DataType VariableName
  DataType : The type of data that the variable can hold

  VariableName : the variable we declare for hold the values.


The varibles in C#, are categorized into the following types:
  • Value types
  • Reference types
  • Pointer types

(a)Value Types:
 If a variable holds actual value then the type of data types are value types. Value type variables can be assigned a value directly. They are derived from the class System.ValueType. These value types are stored in “stack” memory and these value types are fixed in size. If you assign a value of a variable to another variable it will create two copies.
Ex: byte, short, int, float, double, long ,char, bool, DateTime.
All primitive data type except string and object are example of value types.
Object is a super type. It can store any type and any size of data. Object is called super type because it helps in inheritance.
struct and enum are value type.
CSharp has a set of predefined value types

No comments

Powered by Blogger.