Results 1 - 5 of 11

What is C#?


C# (pronounced as C-Sharp) is an Object Oriented programming language developed by Microsoft. This language is very similar to Java and was developed to bring together C++ features and the easy programming of Visual Basic (VB).

Difference between C++ and C#?


C#

      C# is a higher level programming language built over C++ programming language.

      It is similar to Java.

      It can be considered as a hybrid programming language consisting of features of C++ and ease of use of VB.Net.
C++

      C++ is a low level programming language built by adding object oriented concepts to the C programming language.

      It is NOT similar to Java.

      C++ itself is a language and does not inherit any features of other languages.

What is Struct and Class in C#?


Struct

      
Value Type i.e. whenever a variable is created, it holds the value.

      Copying a Struct variable, copies the value.

      A new variable is created in Stack memory.

      Cannot be inherited.

      Cannot be of Abstract type.

      Cannot contain Private parameterless constructors.

      Doesn’t support Destructor.
 
Class

      Reference Type i.e. whenever a variable is created, it holds the reference (address) while the value is stored some location.

      Copying a Class variable, copies the reference while the value remains on same location.

      A new variable is created in Heap memory.

      Can be inherited.

      Can be of Abstract type.

      Can contain Private parameterless constructors.

      Supports Destructor.

Difference between String and StringBuilder in C#?


String

      Belongs to the System namespace.

      Immutable i.e. whenever you append a String object it creates a new object with new memory allocation.

      When changed, a new object is created and old object is destroyed.

      Avoid using inside loops, as if the loop executes N times. N memory allocation operations will be performed.

      Concat function is used for String concatenation.
Example:
string s = "Mudassar";
s = string.Concat(s, "Khan");
 
StringBuilder

      Belongs to the System.Text namespace.

      Mutable i.e. whenever you append a String object it does not creates a new object with new memory allocation.

      When changed, no new object is created or old object is destroyed.

      Recommended for loops, as only the size of object will change.

      Append function is used for String concatenation.
Example:
StringBuilder sb = new StringBuilder();
sb.Append("Mudassar");
sb.Append("Khan");

What is Static function and example of in-built Static function in .Net?



      Has the keyword static.

      A Static function is one that can be accessed without creating an object of the class.

      It can be accessed using the name of the class.

      It can belong to Static as well as Non-Static classes.

      One cannot use external Non-Static objects and functions inside a Static method.

      One can use Static function in Static as well as Non-Static classes.

      Keyword this is not supported.

      Example of one inbuilt Static function in C# is Convert.ToString().
Example:
public class A
{
    public static void C()
    {
        //Invalid
        this.D();
    }
    public void D()
    {
        //Valid
        C();
    }
}

Results 1 - 5 of 11