Saturday, March 16, 2019

Default Access Modifier

                     | Default   | Permitted declared accessibilities
------------------------------------------------------------------
namespace            | public    | none (always implicitly public)

enum                 | public    | none (always implicitly public)

interface            | public    | none

class                | Internal   | All¹

struct               | private   | public, internal, private²

delegate             | private   | All¹

constructor          | private   | All¹

interface member     | public    | none (always implicitly public)

method               | private   | All¹

field                | private   | All¹

user-defined operator| none      | public (must be declared public)

Class Default   - Internal  use below link
https://www.c-sharpcorner.com/UploadFile/84c85b/default-scope-of-a-C-Sharp-class/

What is constant and Readonly

 What is Difference Between constant and readonly.

Ans:

const
  • They can not be declared as static (they are implicitly static)
  • The value of constant is evaluated at compile time
  • constants are initialized at declaration only
readonly
  • They can be either instance-level or static
  • The value is evaluated at run time
  • readonly can be initialized in declaration or by code in the constructor

imp

const: Can't be changed anywhere.
readonly: This value can only be changed in the constructor. Can't be changed in normal functions



.NET Framework and Architecture


What is .Net Framework.

It is a platform to develop application.

============================================================

Difference between Visual Studio and VS.NET

Visual StudioVisual Studio .Net
It is object basedIt is object oriented
Internet based application
- Web Application
- Web services
- Internet enable application
- Third party API
- Peer to peer Application
All developing facilities in internet based application
Poor error handling Exception/ErrorAdvance error handler and debugger
Memory Management System Level TaskMemory Management Application Domain with help of GC (Garbage Collector)
DLL HELLVS .NET has solved DLL HELL Problem


What is DLL Hell:


I have two applications, A and B installed, both of them installed on my PC.
Both of these applications use the same shared assembly SharedApp.dll.

Somehow, I have the latest version of SharedApp.dll installed on my PC.
The latest SharedApp.dll replaces the existing DLL, that App A was also using earlier.
Now App B works fine whereas App A doesn't work properly due to the newer SharedApp.dll.



DLLHELL1.jpg





Solution of Dll-Hell Problem 

This problem of dynamic link library (.dll) is resolved through Versioning.



versin mmmmm.GIF



What is GAC(Global Assembly Cache):


The GAC implements the feature of shared library where different applications reuse the code placed in the files located in a common folder. 



What is Assembly:


An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file.

it is Unit of Deployment. like EXE or DLL.

==============================================================
What is Difference between EXE and DLL

Ans:

1.EXE is an extension used for executable files while DLL is the extension for a dynamic link library.
2.An EXE file can be run independently while a DLL is used by other applications.
3.An EXE file defines an entry point while a DLL does not.
4.A DLL file can be reused by other applications while an EXE cannot.
5.A DLL would share the same process and memory space of the calling application while an EXE creates its separate process and memory space.






Types of Assembly:

  1. private
  2. shared (Public assembly)
  3. sattelite Assembly 

Private Assembly
 
Private assembly requires us to copy separately in all application folders where we want to use that assembly’s functionalities; without copying we cannot access the private assembly features and power. Private assembly means every time we have one, we exclusively copy into the BIN folder of each application folder.



2. Shared Assembly

Assemblies that can be used in more than one project are known to be a shared assembly. Shared assemblies are generally installed in the GAC. Assemblies that are installed in the GAC are made available to all the .Net applications on that machine.

However there are two more types of assemblies in .Net, Satellite Assembly and Shared Assembly. 


Satellite Assembly
 
Satellite assemblies are used for deploying language and culture-specific resources for an application.


GAC:

GAC stands for Global Assembly Cache. It is a memory that is used to store the assemblies that are meant to be used by various applications. 


 











Saturday, March 9, 2019

what is Structure in c#

=>Structure is a value type data type.

=>It helps you to make single variable to hold related data in different data types.

Points to Remember:

Structures can have methods, fields, indexers, properties, operator methods, and events.

Structures can have defined constructors, but not destruction. However, you cannot define a default constructor for a structure. The default constructor is automatically defined and cannot be changed.

Unlike classes, structures cannot inherit other structures or classes.

Structures cannot be used as a base for other structures or classes.

A structure can implement one or more interfaces.

Structure members cannot be specified as abstract, virtual, or protected.

When you create a struct object using the New operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the New operator.

If the New operator is not used, the fields remain unassigned and the object cannot be used until all the fields are initialized.



*** If you want to initialize fields inside the struct it get compile error.


  1. struct MyStruct {  
  2.     int x = 20; // Error its not possible to initialize  
  3.     int y = 20; // Error its not possible to initialize  
  4. }  



Class versus Structure
  • Classes and Structures have the following basic differences
  • classes are reference types and structs are value types
  • structures do not support inheritance
  • structures cannot have default constructor


Example:

  struct Books
    {
        public string Tittle;
        public string BookName;
        public int bookId;
    }

    class Program
    {
     
        static void Main(string[] args)
        {
            Books b1;
            b1.Tittle = "XYZ";
            b1.BookName = "Name";
            b1.bookId = 1;


            Books obj = new Books();
            obj.Tittle = "Alok";
            Console.WriteLine(b1.BookName);
            Console.ReadLine();


        }
    }





Sunday, February 24, 2019

What is Indexer

An Indexer is a special type of property that allows a class or structure to be accessed the same way as array for its internal collection. It is same as property except that it defined with this keyword with square bracket and parameters.



Example:

class StringDataStore
{
   
    private string[] strArr = new string[10]; // internal data storage

    public string this[int index]
    {
        get
        {
            if (index < 0 &&  index >= strArr.Length)
                throw new IndexOutOfRangeException("Cannot store more than 10 objects");

                return strArr[index];
        }

        set
        {
            if (index < 0 ||  index >= strArr.Length)
                throw new IndexOutOfRangeException("Cannot store more than 10 objects");

            strArr[index] = value;
        }
    }
}


Thursday, February 21, 2019

What is Anonymous Method

anonymous method is a method without a name. Anonymous methods in C# can be defined using the delegate keyword and can be assigned to a variable of delegate type.


Example:

 public delegate int DelegateResultNum(int p);
        static int num = 100;
        delegate int Getnummber(int x, int Y);


        public static int Add(int x)
        {
            num += x;
            return num;
        }

        public static int multiple(int y)
        {
            num *= y;
            return num;
        }

        public static int getnum()
        {
            return num;
        }

        static void Main(string[] args)
        {
            DelegateResultNum num1 = new DelegateResultNum(Add);

            //Anonymous Method
            Getnummber d1 = delegate (int r, int z) { return r * z; };
            d1(4,5);
       
            num1(12); ;
            int x = getnum();

            Console.WriteLine(x);



        }

what is CLR,CTS,CLS

The Common Language Runtime (CLR) is the programming (Virtual Machine component) that manages the execution of programs written in any language that uses the .NET Framework, for example C#, VB.Net, F# and so on.


Function of CLR.


  • Convert code into CLI.
  • Exception handling
  • Type safety
  • Memory management (using the Garbage Collector)
  • Security
  • Improved performance
  • Language independency
  • Platform independency
  • Architecture independency.

Component of CLR
  • Class Loader

    Used to load all classes at run time.
     
  • MSIL to Native code

    The Just In Time (JTI) compiler will convert MSIL code into native code.
     
  • Code Manager

    It manages the code at run time.
     
  • Garbage Collector

    It manages the memory. Collect all unused objects and deallocate them to reduce memory.
     
  • Thread Support

    It supports multithreading of our application.
     
  • Exception Handler

    It handles exceptions at run time.


What is CTS and CLS:

C# has int Data Type and VB.Net has Integer Data Type. Hence a variable declared as int in C# or Integer in vb.net, finally after compilation, uses the same structure Int32 from CTS.

Note:

All the structures and classes available in CTS are common for all .NET Languages and the purpose of these is to support language independence in .NET. Hence it is called CTS.



CLS(Common language specification):

CLS stands for Common Language Specification and it is a subset of CTS. It defines a set of rules and restrictions that every language must follow which runs under .NET framework.