What is .Net Frame Work?
The .NET Framework has two main components: the common language runtime and the .NET Framework class library.
You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that ensure security and robustness.
The class library, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.
Feature | Interface | Abstract class |
Multiple inheritance | A class may inherit several interfaces. | A class may inherit only one abstract class. |
Default implementation | An interface cannot provide any code, just the signature. | An abstract class can provide complete, default code and/or just the details that have to be overridden. |
Access Modfiers | An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public | An abstract class can contain access modifiers for the subs, functions, properties |
Core VS Peripheral | Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface. | An abstract class defines the core identity of a class and there it is used for objects of the same type. |
Homogeneity | If various implementations only share method signatures then it is better to use Interfaces. | If various implementations are of the same kind and use common behaviour or status then abstract class is better to use. |
Speed | Requires more time to find the actual method in the corresponding classes. | Fast |
Adding functionality (Versioning) | If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. | If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. |
Fields and Constants | No fields can be defined in interfaces | An abstract class can have fields and constrants defined |
1> CLR uses the Dispose and Finalize methods for performing garbage collection of runtime objects of .Net applications.
2> Clr has a Garbage Collector(GC) which periodically checks for unused and unreferenced objects in Heap.It call Finalize() method to free the memory used by such objects.
3> Dispose is another method which is invoked by Garbage Collector to release the memory occupied by an object.Dispose method needs to be explicitly called in code for removing an object from Heap.
4> Dispose method can be invoked only by the classes that IDisposable interface.
However it is considered as a single class by CLR. Infact if we can take a look into IL code we will find a single class only. So two developers can work on their own copy of partial class.
We can keep all properties related to Employee in one Employee Partial Class.
We can keep all Methods related to Employee in one Employee Partial Class.
We can keep all constants and fields related to Employee in one Employee Partial Class and so on.
How does Cookies differ from Session Variables?
2) Cookies created on browser.
3) Cookies can be disabled by user computer.
2) Session created on the Server.
What is portable executable (PE)?
What is Application Domain?
The primary purpose of the AppDomain is to isolate an application from other applications. Win32 processes provide isolation by having distinct memory address spaces. This is effective, but it is expensive and doesn't scale well. The .NET runtime enforces AppDomain isolation by keeping control over the use of memory - all memory in the AppDomain is managed by the .NET runtime, so the runtime can ensure that AppDomains do not access each other's memory.
Objects in different application domains communicate either by transporting copies of objects across application domain boundaries, or by using a proxy to exchange messages.
MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.
How does an AppDomain get created?
AppDomains are usually created by hosts. Examples of hosts are the Windows Shell, ASP.NET and IE. When you run a .NET application from the command-line, the host is the Shell. The Shell creates a new AppDomain for every application.
AppDomains can also be explicitly created by .NET applications. Here is a C# sample which creates an AppDomain, creates an instance of an object inside it, and then executes one of the object's methods. Note that you must name the executable 'appdomaintest.exe' for this code to work as-is.
using System;
using System.Runtime.Remoting;
public class CAppDomainInfo : MarshalByRefObject
{
public string GetAppDomainInfo()
{
return "AppDomain = " + AppDomain.CurrentDomain.FriendlyName;
}
}
public class App
{
public static int Main()
{
AppDomain ad = AppDomain.CreateDomain( "Andy's new domain", null, null );
ObjectHandle oh = ad.CreateInstance( "appdomaintest", "CAppDomainInfo" );
CAppDomainInfo adInfo = (CAppDomainInfo)(oh.Unwrap());
string info = adInfo.GetAppDomainInfo();
Console.WriteLine( "AppDomain info: " + info );
return 0;
}
}
What is Code Access Security (CAS)?
CAS is the part of the .NET security model that determines whether or not a piece of code is allowed to run, and what resources it can use when it is running.
What is Event - Delegate? Clear Syntax for writing a Event Delegate
The event keyword lets you specify a delegate that will be called upon the occurrence of some "event" in your code. The delegate can have one or more associated methods that will be called when your code indicates that the event has occurred. An event in one program can be made available to other programs that target the .NET Framework Common Language Runtime.
// keyword_delegate.cs
// delegate declaration
delegate void MyDelegate(int i);
class Program
{
public static void Main()
{
TakesADelegate(new MyDelegate(DelegateFunction));
}
public static void TakesADelegate(MyDelegate SomeFunction)
{
SomeFunction(21);
}
public static void DelegateFunction(int i)
{
System.Console.WriteLine("Called by delegate with number: {0}.", i);
}
}
What is Strong Name?
What is CLR, CTS and CLS?
The .NET Framework provides a runtime environment called the Common Language Runtime or CLR (similar to the Java Virtual Machine or JVM in Java), which handles the execution of code and provides useful services for the implementation of the program. CLR takes care of code management at program execution and provides various beneficial services such as memory management, thread management, security management, code verification, compilation, and other system services. The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging.
Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution.
Web Farm is running an application in more than one computer.
Web Garden is running an application in single computer with multiple processor.
What is Typed Dataset in C#?
What is Load balancing?
Difference between Clone and Copy?
Dataset. Copy :- Copies both Structure and data.
Main Difference between Array list and Hash Table?
Array list:
Array list is a collection of objects (may be of different types).
Array list is very much similar to array but it can take values of different data types.
If you want to find something in a array list you have to go through each value in array list, theres no faster way out.
Array List’s size can be changed dynamically.
Hash table:
Hash table is also collection which takes a key corresponding to each value.
If you want to find something in a hash table you don’t have to go through each value in hash table, instead search for key values and is faster.
Secondly Array list is slower as compare to Hash table.
Hash table is basically use for maintaining huge data but array list don’t have.
The difference is also on the interfaces they implement.
The Array List Class implements the ICollection (allows us to use the Count property to count the number of items in the List), IList (allows for the use of Add , Remove, Clear, Insert methods to maipulate the items in the List) and IEnumerable and IEnumerator(allows for using the [for each - in] to traverse through the items)
The Hash table implements the IDictionary interface that instead of mapping the items with indexes represents the items as key/value pairs.
The ICollection extends the IEnumerable;
The IDictionary and the IList extend the ICollection
Main Difference between Application and Session and Cookies?
The session object is used to maintain the session of each user. If one user enter in to the application then they get session id if he leaves from the application then the session id is deleted. If they again enter in to the application they get different session id.
But for application object the id is maintained for whole application. It doesn't differ
State Management in APS.NET is managed by two ways:
Client-Side or Server-Side
Client-Side:Cookies,HiddenFields,ViewState and Query Strings.
Serve-Side:Application,Session and Database.
COOKIE:
A cookie is a small amount of data stored either in a text file on the client's file system or in-memory in the client browser session. Cookies are mainly used for tracking data settings. Let’s take an example: say we want to customize a
welcome web page, when the user request the default web page, the application first to detect if the user has logined before, we can retrieve the user informatin from
cookies:
[c#]
if (Request.Cookies[“username”]!=null)
lbMessage.text=”Dear “+Request.Cookies[“username”].Value+”,
Welcome shopping here!”;
else
lbMessage.text=”Welcome shopping here!”;
If you want to store client’s information, you can use the following code:
[c#]
Response.Cookies[“username’].Value=username;
So next time when the user request the web page, you can easily recongnize the user again.
SESSION:
Session object can be used for storing session-specific information that needs to be maintained between server round trips and between requests for pages. Session object is per-client basis, which means different clients generate different session object.The ideal data to store in session-state variables is short-lived, sensitive data that is specific to an individual session.
Each active ASP.NET session is identified and tracked using a 120-bit SessionID string containing URL-legal ASCII characters.
Every web application must have a configuration file named
web.config, it is a XML-Based file, there is a section
name ‘sessionState’, the following is an example:
sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20" />
‘cookieless’ option can be ‘true’ or ‘false’. When it is ‘false’(default value), ASP.NET will use HTTP cookie to identify users. When it is ‘true’, ASP.NET will randomly
generate a unique number and put it just right ahead of the requested file, this number is used to identify users
[c#]
//to store information
Session[“myname”]=”Mike”;
//to retrieve information
myname=Session[“myname”];
this is briefly about cookies and sessions in ASP.NET
Cookies :
1. Cookies can store only "string" datatype
2. They are stored at Client side
3. Cookie is non-secure since stored in text format at client side
4. Cookies may or may not be individual for every client
5. Due to cookies network traffic will increase.Size of cookie is limited to 40 and number of cookies to be used is restricted to 20.
6. Only in few situations we can use cookies because of no security
7. We can disable cookies
8. Since the value is string there is no security
9. We have persistent and non-persistent cookies
Session :
1. Session can store any type of data because the value is of datatype of "object"
2. These are stored at Server side
3. Session are secure because it is stored in binary format/encrypted form and it gets decrypted at server
4. Session is independent for every client i.e individual for every client
5. There is no limitation on size or number of sessions to be used in an application
6. For all conditions/situations we can use sessions
7. we cannot disable the sessions. Sessions can be used without cookies also(by disabling cookies)
8. The disadvantage of session is that it is a burden/overhead on server
9. Sessions are called as Non-Persistent cookies because its life time can be set manually
No comments:
Post a Comment