Sunday, April 6, 2014

Data Types of C#.Net Interview Questions(26)

Data Types of C#.Net Interview Questions(26)



1.How Data types can be Categorized in C#.Net?
A) Data types can be Categorized into two types they are
              Ø  Value Types
              Ø  Reference Types

2.What are the  broad classifications of data types available in C#?
A)Data types can be broadly divided into 2 types.They are:
1. Built in data types.
2. User defined data types.
3.List Some of the Built in datatypes in C#?
A)Smoe of exteremed built in datatypes in c# are:
            Ø  Int
           Ø  Float
           Ø  String
 
4.List the Different types in c#.Net?
A)
DataType
Common Language Runtime Structure
StorageAllocation
Value Range
Boolean
System.Boolean
2 bytes
True or False.
Byte
System.Byte
1 byte
0 through 255 (unsigned).
Char
System.Char
2 bytes
0 through 65535 (unsigned).
Date
System.DateTime
8 bytes
0:00:00 on January 1, 0001 through 11:59:59 PM on December 31, 9999.
Decimal
System.Decimal
16 bytes
0 through +/-79,228,162,514,264,337,593,543,950,335 with no decimal point;
0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest nonzero number is
+/-0.0000000000000000000000000001 (+/-1E-28).
Double
(double-precision floating-point)
System.Double
8 bytes
-1.79769313486231570E+308 through
-4.94065645841246544E-324 for negative values; 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values.
Integer
System.Int32
4 bytes
-2,147,483,648 through 2,147,483,647.
Long
(long integer)
System.Int64
8 bytes
-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.
Object
System.Object (class)
4 bytes
Any type can be stored in a variable of type Object.
Short
System.Int16
2 bytes
-32,768 through 32,767.
Single
(single-precision floating-point)
System.Single
4 bytes
-3.4028235E+38 through -1.401298E-45 for negative values; 1.401298E-45 through 3.4028235E+38 for positive values.
String
(variable-length)
System.String (class)
Depends on implementing platform
0 to approximately 2 billion Unicode characters.
User-Defined Type
(structure)
(inherits from System.ValueType)
Depends on implementing platform
Each member of the structure has a range determined by its data type and independent of the ranges of the other members.
In this Data Types can be categroized in C#.Net.
For More Info Visit:

5.What are the default values for bool,int,double,string,char,reference-type variables?
A)When the types are declared then they have default values during declaration.It can be listed in below  tabular format.
Type
Default Value
bool
False
int
0
double
0
string
“”
char
‘’
Reference type
Null

6.If you declare a variable without any value assignment  either of bool,int,double,string,char?
A)It gives an error because bool,int,double,string,char types are value types.All value types requires values.

7. How to declare a constant variable in C#? What is the use of the const keyword?
A)If a variable needs to have a fixed value, that may not be changed across the application's
life, then it may be declared with the const keyword. The value assigned to a constant variable (using the const keyword) must be known at the time of compilation.

8.Can we assign a “null” to value types?
A)Yes if we make value types as a nullable types.
    E.G:int ?a=null  //Is valid(It is nullable type declaration)
           int a=null //Is not valid  
9.What is Nullable types?
A) Nullable types are instances of the Nullable struct. A nullable type can represent the correct range of values for its underlying value type, plus an additional null value. For example, a Nullable, pronounced "Nullable of Int32," can be assigned any value from -2147483648 to 2147483647, or it can be assigned the null value. A Nullable can be assigned the values true false, or null.


10.What is Const?
A)Const values won’t be changed.It can be declared as compile time.use “const” keyword to declare a variable as constant.
   E.G: const int a=2;

11.What is Readonly?
A)These values will be evaluated at runtime.Even we can declare at compile time and it changes  according to runtime declaration.Use “Readonly” keyword to declares a variable as readonly.
E.G:readonly int b;
12.What is the difference between const and read only?
A)
Const
Read-only
Const can only be initialized at the time of declaration of the field.

The value will be initialized either declaration time or the constructor of the class allowing you to pass the value at run time.
Const values will evaluate at compile time only.

Read only values will evaluate at runtime only.

Const value can’t be changed these will be same at all the time.

Read-only value can be changed at runtime.


13.How do you create user defined data types in C#?
A)You use the struct, class, interface, and enum constructs to create your own custom types. The .NET Framework class library itself is a collection of custom types provided by Microsoft that you can use in your own applications.
14.What is keywords in C#.Net?
A)Keywords are predefined reserved identifiers that have special meaning to the compiler.Keywords cannot be used as variables in your program unless they include @ as a prefix.
15.How many types of keywords are there in C#.Net.List them?
A)C#.Net Supports 2 types of keywords.They are:
                 Ø  Reserved Keywords
                 Ø  Contextual Keywords
   There are 77 Reserved keywords and 6 contextual keywords present in C#.Net.

16.What is the case used for keywords in C#.Net?
A)Lower case is used to represent the keywords in C#.Net.
17.List some of Reserved Keywords in C#.Net?
A)abstract,event,new,struct,as,explicit,null,switch,base,extern etc……………..
18.List Contextual Keywords?
A)There are 6 contextual keywords are there.They are:
               1.      Get
               2.      Partial
               3.      Set
               4.      Value
               5.      Where
               6.      Yield
Contextual keyword is used to provide a specific maning in the code,but it is not a reserved word in C#.Net

19.Define “Get”?
A)”Get” defines an acessor method or a property or an indexer.

20.Define “Set”?
A) ”Set” defines an acessor method or a property or an indexer.

21.Define Partial ?
A)It defines an classes,structs and interfaces throughout the same compilation unit

22.Define Where?
A)It adds constraints i.e conditions to a generic declaration.

23.Define Yield?
A)It is used an iterator block to return a value to the enumerator object or to signal the end of iteration.

24.Define value?
A)Used to set accessors and to add or remove event handlers.

25.What is a line terminator in C#.Net?
A)Semicolon(;) is a line terminator in C#.Net.

26.What are the Program Control Structures in C#.Net?
A)In C#.Net Program Control Structures can be classified into following types.They are:
              Ø  Conditional Statements(Simple If,If Else,Nested If)
              Ø  Iteration or Looping type of statements(For,Ehile,Do While,Foreach)
              Ø  Other types(Break,continue,jump,etc..)

0 comments:

Post a Comment