Wednesday, 12 April 2017

Is C# code is managed or unmanaged code?

C# is managed code because Common language runtime can compile C# code to Intermediate language.



Imp points -

.Net supports two type of coding-

Managed Code
Unmanaged Code

Managed Code-
The resource, which is with in your application domain is, managed code. The resources that are within domain are faster.

The code, which is developed in .NET framework, is known as managed code. This code is directly executed by CLR with help of managed code execution. Any language that is written in .NET Framework is managed code.

Managed code uses CLR which in turns looks after your applications by managing memory, handling security, allowing cross - language debugging, and so on.

Unmanaged Code-

The code, which is developed outside .NET, Framework is known as unmanaged code.
Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system. Background compatibility with code of VB, ASP and COM are examples of unmanaged code.
Unmanaged code can be unmanaged source code and unmanaged compile code.
Unmanaged code is executed with help of wrapper classes.
Wrapper classes are of two types: CCW (COM Callable Wrapper) and RCW (Runtime Callable Wrapper).
Wrapper is used to cover difference with the help of CCW and RCW.






Wednesday, 5 April 2017

Strings In C#

Strings

A string is a sequence of characters stored in a certain address in memory.
In. NET Framework each character has a serial number from the Unicode table.

The System.String Class-- String KeyWord used for String Creation

string greeting = "Hello, C#";

Collections in C#

Collections

The types in the Framework for collections can be divided into the following categories: -
Interfaces that define standard collection protocols •
Ready-to-use collection classes (lists, dictionaries, etc.) •
Base classes for writing application-specific collections

Collection Namespace As Follows -

System.Collections                                                  Nongeneric collection classes and interfaces
System.Collections.Specialized                              Strongly typed nongeneric collection classes System.Collections.Generic                                    Generic collection classes and interfaces System.Collections.ObjectModel                            Proxies and bases for custom collections System.Collections.Concurrent                                   Thread-safe collections

Multithreading??

A thread is defined as the execution path of a program. Each thread defines a unique flow of control.



Thread Life Cycle

The life cycle of a thread starts when an object of the System.Threading.Thread class is created and ends when the thread is terminated or completes execution.
Following are the various states in the life cycle of a thread:
  • The Unstarted State: It is the situation when the instance of the thread is created but the Start method is not called.
  • The Ready State: It is the situation when the thread is ready to run and waiting CPU cycle.
  • The Not Runnable State: A thread is not executable, when:
    • Sleep method has been called
    • Wait method has been called
    • Blocked by I/O operations
  • The Dead State: It is the situation when the thread completes execution or is aborted.
System.Threading.Thread

Thursday, 31 March 2016

Boxing and unBoxing

Boxing – This is the process of converting from value type to reference type. For example,
int myvar = 10;
object myObj = myvar;
UnBoxing – It’s completely opposite to boxing. It’s the process of converting reference type to value type. For example,
int myvar2 = (int)myObj;

Write a sample code to write the contents to text file in C#?

Below is the sample code to write the contents to text file –
Using System.IO;
File.WriteAllText(”mytextfilePath”, “MyTestContent”)

What is the difference between “continue” and “break” statements in C#?

  • “continue” statement is used to pass the control to next iteration. This statement can be used with – “while”, “for”, “foreach” loops.
  • “break” statement is used to exit the loop