About

Sunday, September 29, 2019

Basic garbage collection

In the common language runtime (CLR), the garbage collector serves as an automatic memory manager. 
It provides the following benefits:
  • Enables you to develop your application without having to manually free memory for objects you create.
  • Allocates objects on the managed heap efficiently.
  • Reclaims objects that are no longer being used, clears their memory, and keeps the memory available for future allocations. Managed objects automatically get clean content to start with, so their constructors do not have to initialize every data field.

Garbage Collection in C# Interview Question 


What is Garbage Collection

Garbage collection is one of most important future in the .Net Framework environment

Futures : 

1. When we have a class that represents an object in the runtime that allocates a memory space in the heap memory.

2. When there isn't enough memory to allocate an object, the GC must collect and dispose of garbage memory to make memory available for ne allocations


3. You can force garbage collection either to all the three generations or to a specific generation using the GC.Collect() method the GC.Collect() Method is overloaded you can call it without any parameters or event by passing the generation number you would like to the garbage collector to collect.

4 it determines when an instanciated class is no longer in using and reclaims memory.

5. The .Net  language does not do so the CLR does so. that's why its called "automatic garbage collection"

There are three type in generation :



Wednesday, September 25, 2019

.Net Core C# Revers String functionality without using .string.revers function 
: Interview questions 

Without using any .net revers string functionality. we can develop our own revers string function with using below code example


Example Code

static StringBuilder stringBuilder = new StringBuilder();
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Prasad KM");
           
            ReverseString("PrasadKM", 8);
            Console.WriteLine("First time string(PrasadKM) revers string :  " + stringBuilder.ToString());
         

string tempdata = stringBuilder.ToString();
            stringBuilder = new StringBuilder();

            ReverseString(tempdata, 8);
            Console.WriteLine("Second time string(MKdasarP) revers string :   " + stringBuilder.ToString());
            Console.Read();
        }

//Reflection Method
        static void ReverseString(string str, int len)
        {
            if (len <= 0)
                return;
            stringBuilder.Append(str[len - 1]);
            ReverseString(str, --len);
        }

//For each functionality
 static void ReverseString1(string str)
        {
           
            for (int i = str.Length-1; i <= str.Length; i--)
            {
                if (i < 0) break;
                stringBuilder.Append(str[i]);
            }
        }

OutPut


Conclusion : Without using .net string revers functionality, we can develep the our own revers string functionality with above code.

Please add your comments:

Tuesday, September 24, 2019

Execute one async and normal method  C#


We have two methods in below example 
1. Without await functionality with async key word
2. Without await and async method/functionality(normal method )

The below example is  methods will be executing in  asynchronous action.

Example : 
 static void Main(string[] args)
        {
            GetTaskAsync();
            NormalMethod();
            Console.Read();
        }
        static async Task  GetTaskAsync()
        {
            await Task.Run(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine(" GetTaskAsync");
                }
            });
        }

        static void NormalMethod()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(" NormalMethod");
            }
        }
    }

OutPut : 

Conclusion : As per above points with async and with out await key words the functionality will work like asynchronous

Please add the comments then I can improve the blog thank you


Async and await  C# .Net


What is Async C#?

async functionality/methods runs/executes until it reaches it's first await functionality and until the awaited task is complete.

Async key will support only when it modifies a method and lambda expression or anonymous functionality.

Example 1 :

static void Main(string[] args)
        {
            Int32 VariableName = 0;
            Console.WriteLine("GetTaskAsync1 - Started  Thread ID " + System.Threading.Thread.CurrentThread.ManagedThreadId);
            GetTaskAsync1();
            Console.WriteLine("GetTaskAsync1 - End  Thread ID " + System.Threading.Thread.CurrentThread.ManagedThreadId);

            Console.Read();
        }

        static async Task GetTaskAsync1()
        {
            Console.WriteLine("GetTaskAsync2 - Started  Thread ID " + System.Threading.Thread.CurrentThread.ManagedThreadId);
            int result = await GetTaskAsync2();
            Console.WriteLine("result : "+ result);
            Console.WriteLine("GetTaskAsync2 - End  Thread ID " + System.Threading.Thread.CurrentThread.ManagedThreadId);
        }
        static async Task<int> GetTaskAsync2()
        {
            int count = 0;
            for (int i = 0; i < 1000; i++)
            {
                count++;
            }
            return count;
        }
    }

Conclusion :  if we use async and await key then the functionality will run in synchronous action and the functionality will run in background thread.


Please add the comments then I can improve the blog thank you



Monday, September 16, 2019

CLR : Common Language Runtime 


The Runtime Environment of .NET Framework is Called Common Language Runtime.  It manages the execution of Managed Code (.NET Programs). 

CLR uses a just-in-time (JIT) compiler which converts the compiled code of .NET into Native Code.

Example : 

Language Compilers (e.g. C#, VB.Net, J#) convert the .NET Program Code to Microsoft Intermediate Language (MSIL) and this is further converted to Native Code by JIT Compiler of CLR.



Functionality  Of CLR

CLR provides many functionality like it loads and executes the code, manages the memory, converts the MSIL code to native code, and handles the exception.

CLR will support below functionality:

  • Memory Management
  • Code Access security
  • Garbage Collection
  • JIT Compilation
  • Thread Support
  • Debug Engine
  • Exception Handling 


Conclusion :  This tutorial will teach you how CLR works in dot net frame functionality.







Dot Net Introduction

Dot Net is a software framework which is designed and developed by Microsoft 
Dot Net is a framework and it is development platform, it will support more then one programming language to run/execute applications.

It will support more then 24 programming languages 

Example : 
1. C#
2. VB.net
3. F#
4 etc..

Dot net framework architecture 


1. C# : 

  • NET isn't just a library, but also a runtime for executing applications.
  • The knowledge of C# implies some knowledge of .NET (because the C# object model corresponds to the .NET object model and you can do something interesting in C# just by using .NET libraries). The opposite isn't necessarily true as you can use other languages to write .NET applications
  • One of the best program language and very easy to learn development functionality.This is very user/developer  friendly language.  

2. CLS( Common language specification) : 


CLS stands for common language specification and it is a subset of CTS(Common type system). it defines a set of rules and restrictions that every language must follow which runs under the dot net framework. the language which follow these set of rules are said to be CLS complaint. 
Example : 
if we consider about C# and etc... languages, in each statement end with semicolon.

C# program : 
static void Main(string[] args)
{
            Console.WriteLine("Hello Prasad KM");
            Console.Read();
}

But in VB.Net each statement should not end with semicolon(;)

3. CTS(Common type system):

Common type system describe the datatypes that can be used by managed code. CTS define how these types are declared. Used and managed in the runtime . cross-language integration type safety and high performance code execution 

Example :  Int32 VariableName = 0;




Conclusion :  
1. Dot net framework is common developer platform, it will support more then 14 languages.
2. CLS and CTS is very important for to understand dot net framework architecture functionality 

Summary : This is completely basic knowledge for to understand dot net functionality.

Please add your comments. thank you.







Sunday, September 15, 2019

Start New Project with Visual Studio Community version


Step 1 : Start/Open Visual Studio
Step 2 : 
File --> New-->Projects
  
Step 3 : Create New Console Project


Step 4 : Add hello word text and run the project

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Prasad KM");
            Console.Read();
        }
    }
}
Step 5 : Press build -->Build Solution(No compile error)
Step 6 : Press Debug-->Run the project
Step 7 : Expected result in console prompt 

Hello Prasad KM on console application prompt:




Conclusion :
How we can create the simple application using visual studio.

Some one can suggest me I have missed in above steps thank you











How we can install the Visual Studio community


Step 1 :
Open Micro Soft web site : 

Step 2 Please find below yellow colour marks. 


Step 3 :
Install all functionality with using below image selection for dot net functionality.

Step 4 : Start your own project.


Conclusion : 
This page will teach you how we can install the visual studio community version.

Summary :  
Visual Studio community version is free for developer and students.