Differences between C++ and C# with examples


Main method

In C++, The first character of the main() function must be small
e.g.
   int main () 
{
   int a = 100;
   int b = 200;
}
In C#, The first character of the Main() function must be capitalized and should return either int or void
e.g. 
static int Main(string[] args)
{
  int a = 110;
   int b = 510;
}

Environment

C++ was designed to be a low-level platform-neutral object-oriented programming language.
C# was designed to be a higher-level component-oriented language.

Namespace/HeaderFile

C++ support #include
C# does not support #include, it support using (not same as #include, both are different)

Compilation

C++ code compiles into assembly language.
C# compiles into Intermediate language (IL) which converted into executable code through the process called Just-In-Time compilation.

Faster

C++ codes not compiled into a bytecode, they generate machine code, so its faster.
C# programs are compiled down to a bytecode which causes a JIT to occur when the programs are executed which takes time i.e it is slow.

Pointer/delegates

C++ has the concept of function pointers.
void main () {
   int  value = 2;   // actual variable.
   int  *p;        // pointer variable 
   p = &value;       // store address of value in pointer variable
   cout << "Value of value variable: ";
   cout << value << endl;
   cout << "Address stored in p pointer variable: ";
   cout << p << endl;
   cout << "Value of *p variable: ";
   cout << *p << endl;
}
C# does not have the concept of function pointers. C# has a similar concept called Delegates.
public delegate int DE(int a);
public class C1
{
  public int p(int x)
  {
    return x;
  }
}
class Program
{
static void Main()
{
 C1 c11 = new C1();
 DE d1 = c1.p;
 int i = d1(10);
 Console.WriteLine(i);
  }
}
 

Variable

In C++, uninitialized variables undetected thus result is unpredictable output.
C# checks for uninitialized variables and gives error message at compile time.

Memory manegement:-

In C++, the memory that is allocated in the heap dynamically has to be explicitly deleted.
In C#, memory management is automatically handled by garbage collector.

Exception:-

In C++, The exception can throw by any class.
in C#, The exception can only throw by a class that is derived from the System.Exception class.

Finally Block

C++ does not have finally block exception handling mechanism.
e.g
try 
{
  // code here
}
catch (int ex1) 
{ 
cout << "int exception"; 
}
catch (char ex2) 
{ 
cout << "char exception"; 
}
catch (...) 
{ 
cout << "default exception"; 
}
C# has finally block in exception handling mechanism which contains code that is always executed at the end of try block.
e.g
try 
{
  // code here
}
catch (ApiConnectionSecurityException ex1) 
{ 
Console.WriteLine("Exception caught: {0}", ex1) //using console application
}
catch DivideByZeroException ex2) 
{ 
lblMsg.Text= ex2.Message;
}
catch (Exception ex3) 
{ 
lblMsg.Text= ex2.Message;
}
Note:- The finally block is executed as soon as control leaves a catch or try block, and typically contains cleanup code for resources allocated in the try block, C# allow order of catch blocks correctly.

Access modifiers

in C++ supports three access modifiers public, private, protected.
in C# supports five access modifiers public, private, protected, internal and protected internal.

By Class

In C++, the end of the class definition has a closing brace followed by a semicolon.
class ClassCplus
    {
        static void Main()
        {
           
        }
    };      // close with semicolon
In C#, the end of the class definition has a closing brace alone.
class ClassCsharp
    {
        static void Main()
        {
           
        }
    }      // not close with semicolon


By Struct

C++ struts behave like classes except that the default access is public instead of private.
C# struts can contain only value types The struts is sealed and it cannot have a default no-argument constructor.

By Foreach

C++ does not contain foreach statement.
C# supports foreach statement.

class ForEachSample
    {
        static void Main()
        {
            int[] ListOfArrays = new int[] { 0, 1, 23, 30, 4, 33, 54, 71, 8, 19 };
            foreach (int num in ListOfArrays)
            {
                System.Console.WriteLine(num);
            }
            System.Console.ReadLine();
        }
    }

By Switch

When break statement is not present after statement in switch case than fall through go to next case (in both case code present or not in case statement).
int main () {
   char Security= 'Z';

   switch(Security) {
      case 'A' :
         cout << "For P.M." << endl; 
         break;               
      case 'C' :                //break statement is not present, switch case than fall through go to next case
      case 'D' :               
         cout << "For D.M" << endl;
         break;
      case 'Z' :
         cout << "For President"<< endl;
         break;
      default :
        cout << "Invalid Security" << endl;
   }
   cout << "Your Security is " << Security << endl;
   return 0;
}
In C++ Switch Statement, the test variable cannot be a string.
int main()
{
  switch(std::string("MaaShardaTechnology")) //Compilation error - switch expression of type illegal 
  {
   case "Opt":
  }
}
//Compilation error Because  C/C++ doesn't really support strings as a type.
//It does support the idea of a constant char array but it doesn't really fully understand the notion of a string.
When break statement is not present after statement in switch case than fall through not go to next case (in both case code present or not in case statement).
class Program
   {
      static void Main()
      {
         string Security= 'Z-Type';
         switch(Security) 
          {
             case 'A_Type' :
                   Console.WriteLine(For P.M.);
                   break;               
             case 'C_Type' :                //break statement is not present, switch case than not go to next case
             case 'D_Type' :               
                   Console.WriteLine(For D.M);
                   break;
             case 'Z_Type' :
                   Console.WriteLine(For President);
                   break;
             default :
                   Console.WriteLine(Invalid Security);
     }
              Console.WriteLine(Your Security is {0}, Security);
              Console.ReadLine();
          }
   }
In C# Switch Statement, the test variable can be a string. above example

By Inheritance

C++ supports multiple inheritance.
C# does not supports multiple inheritance.

By Macros

C++ supports macros.
#include 

#define MAX(X,Y) (((X)>(Y)) ? X : Y)

int main () {
   int i, j;
   i = 510;
   j = 205;
   cout <<"The Maximum value is " << MAX(i, j) << endl;
   return 0;
}
But, C# does not supports macros because One of our main design goals for C# is to keep the code very readable

By Type-Safe

C++ is not type-safe.
C# is language type-safe.

By Arrays

C++ arrays are of value type.
C# arrays are of reference type. The tokens "[]" appear following the array type in C#.

By bit Field

C++ supports bit fields.
#include 
#include 

struct {
   unsigned int i;
   unsigned int j;
} s1;

struct {
   unsigned int i: 1;
   unsigned int j: 1;
} s2;
 
int main( ) {

   printf( "Memory size occupied by s1 : %d\n", sizeof(s1));
   printf( "Memory size occupied by s2 : %d\n", sizeof(s2));
   return 0;
}
But, C# does not supports bit fields.

By Data Type

long data type is 32 bits in c++.
Type Bit Repersent Range
long 8bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
long data type is 64 bits in c#.
Type Bit Repersent Range
long 64-bit signed integer type -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807



What is C# - and its features


What is c# (C Sharp)


C# is new computer programming language which is simple because it based on C++ and Java, which is developed by Microsoft Corporation and submitted to the ECMA for standardization and announced to the public in June 2000 with the introduction of .NET.

C# is the only language designed for the .Net Framework.

C# is a fully object-oriented language (i.e support all the three tenets of object-oriented systems 1. Encapsulation 2.Inheritance 3. Polymorphism) that means C# code can be reusable, during execution the assembly is loaded into the CLR.

C# has automatic garbage collection and type safety that enables developers to build a variety of secure and robust applications.

C# use to create Windows client applications, XML Web services, distributed components, client‐server applications, database applications and much more.

Evaluation of Csharp (C#)

C# features:-

  • In microsoft c#, everything is an Object.
  • C# syntax improve many of the complexities of C++ and provides powerful features such as nullable value types, enumerations, delegates, lambda expressions and direct memory access, which are not found in Java.
  • C# simplifies c++ by eliminating operator like "->", "::", pointers(*).
  • C# does not support default arguments.
  • C# does not support the typed of statement.
  • In C#, structs are of value type.
  • C# does not separate class definition from implementation, classes are define and implemented in the same place and therefor there is no need for header file.
  • In C#, Data Types belong to either value type (which is created in the stack) or reference type(which are created in the heap).
  • All the data types in C# are inherited from the object super class, therefore all data type are object type.
  • Abstract of C# cannot be implemented.
  • In C#, a class can inherit implementation from one base class only.
  • In C#, a class or an interface can implement multiple interfaces.
  • Using the new modifier to explicitly hide an inherited member.
  • Calling the overridden base class members from derived classes.
  • C# supports additional c# operators such as "is" and "typeof".
  • In C# use of the extern keyword.
  • It has a huge standard library which is easy to use.
  • It allows for both managed and native code blocks.
  • C# declare null as keyword.
  • We can create object in c# using "new" keyword.
  • C# does not provide any defaults for constructors.
  • In C#, can't access static member via an objects.

What is ASP.NET Web Site Administration Tool and Find its location

ASP.NET Web Site Administration Tool

ASP.NET Website Administration tool is a utility provided along with Microsoft Visual Studio Microsoft Visual Studio which helps you manage user authentication in your Web sites.

Features of ASP.NET Web Site administration tool is available in System.Web.Security namespace which can access by programmatically.

You can become ASP.NET membership with ASP.NET Forms authentication or with ASP.NET, login control. By Using ASP.NET membership we can create new users and we can authenticate to users who visit your site.

Find or location of ASP.NET Web Site Administration Tool

You can find ASP.NET Web Site Administration Tool By many ways...
Find or Location of ASP.NET Web Site Administration Tool
Find or Location of ASP.NET Web Site Administration Tool


First look of ASP.NET Web Site Administration Tool

Web Site Administration Tool First Look
Web Site Administration Tool First Look


If click any tab security, application or provider before become the member of ASP.NET Web Site Administration than show message...
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store. The following message may help in diagnosing the problem: Unable to connect to SQL Server database.

Web Site Administration Tool error Unable to connect to SQL Server database.
Web Site Administration Tool error Unable to connect to SQL Server database.

What is .Net Framework - and its components - CLR, CTS, CLS, JIT, Class library, MSIL (IL)


Origin of .net technology


OLE(Object Linking and Embedding) Technology :-

It is a technology developed by Microsoft and use to embed documents from one application into another application and manipulate object in another application. For developers, it brought OLE Control Extension (OCX).

COM(Component object Model) Technology :-

Each component and model developed and tested independently, and then integrated it and tested in the system, this technology is called COM.
Distribute development across multiple department which enhances software maintainability and reduce the complexity of software.

.Net technology :-

COM provide binary mechanism for intermodule communication is replaced by an intermediate language(IL). IL allow cross language integration, that enable us to developed web application easily.
Three Generation Of Component Model
Three Generation of Component Model

what is asp.net framework

.NET Framework support ASP.NET, as well as Windows Forms development
The .NET Framework consists of three main parts:

.Net framework provide tools for managing user and application interface which enable user to develop desktop and web applications using variety of language.
Windows froms
console Applications
Web Form
Web Service
Architecture Of .Net Framework
Architecture Of .Net Framework

Componenets of .Net Framework

Common language runtime (CLR):-

CLR is a runtime environment in which programs written in c# and other .Net language. i.e CLR is responsible for managing the execution of the code compiled for the .Net platform. it also support cross language interoperability
Component of CLR

Service provide by CLR

.Net framework class library

.Net provide library of base class which help to support the efforts of developers by providing base classes from which developers can inherit. Much of the functionality in the base class reside in the namespace called System.

Common Type system (CTS)

Using CTS, .net framework support multiple language. Basically CTS support Varity of Types and operation of many language, so there is no need type conversion while calling one language from another.

Common language specification (CLS)

CLS is a subset of Common Type system (CTS) that helps third-party compiler designers and library builders and language supporting the CLS can use each other class library.

MSIL (Microsoft intermediate language) or IL (intermediate language)

When compile a programme written in CLS-Compliant language, the source code is compiled into MSIL or IL.

Mange Code

when CLR satisfy the Code at runtime in order to execute forward to managed code. The Compiler that compatible to the >net platform generate managed code.

JIT (Just in Time)

It is used to convert common intermediate language into native code (Machine code).

Different type Of JIT

Execution of programme in CLR and behave of its components
Execution of programme in CLR and behave of its components

Key Points

C#, VB, J# generate only Intermediate language where as c++ generate Intermediate language and native code Native code not store permanently, Every time native code generate whenever execute the programme