<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ghanshyam Thakkar on Medium]]></title>
        <description><![CDATA[Stories by Ghanshyam Thakkar on Medium]]></description>
        <link>https://medium.com/@ghanshyam.skipper?source=rss-3cb194145e9d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zDLtwjcnABX36GYt.jpg</url>
            <title>Stories by Ghanshyam Thakkar on Medium</title>
            <link>https://medium.com/@ghanshyam.skipper?source=rss-3cb194145e9d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:36:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ghanshyam.skipper/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dependency Injection in C#]]></title>
            <link>https://medium.com/@ghanshyam.skipper/dependency-injection-in-c-8a2ece6aaecb?source=rss-3cb194145e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a2ece6aaecb</guid>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[aspnet]]></category>
            <dc:creator><![CDATA[Ghanshyam Thakkar]]></dc:creator>
            <pubDate>Sun, 17 Mar 2024 15:28:13 GMT</pubDate>
            <atom:updated>2024-05-18T14:29:29.439Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome technicians,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZIlKrmlsBFew_YcmoSmtYw.png" /></figure><p>In this blog, i would like to share my knowledge on the topic of Dependency Injection.</p><h3>What is Dependency Injection</h3><p>So simple dictionary meaning of dependency is that someone or something has some dependency on another. It means, someone or something is unable to proceed without another one or another thing.</p><p>If you join a software company, the company must provide laptop to you proceed your work, the internet must be provided to you. Without having these things you can not proceed, correct ?</p><p>If you take an example of car or bike, it depends on fuel, without fuel they can’t proceed.</p><p>So In order to proceed something, some other thing must be provided by someone.</p><p>In the same way, in programming, some class object or some variable values must be provided to some other class or function in order to proceed some functionality.</p><h3>Dependency in Programming</h3><p>Let’s take programming example in C#.</p><p>Let’s suppose i have a function to sum two number</p><pre>public int Sum(int a, int b){<br>   return a+b;<br>}<br></pre><p>We can say that the sum function is depend on two variable values to proceed it’s functionality.</p><p>Let’s take another complex example:</p><p>Let’s say that i have web-api application, and i want my application to keep track of errors or exceptions occurred in application while it is running.</p><p>we generally use to write following code:</p><pre>public class CustomerController : ApiController<br>{<br><br>    [HttpGet]<br>    public IActionResult GetCustomers()<br>    {<br>       try  <br>       {<br>          .... code here for database call to get customers<br>       }<br>       catch(Exception ex)<br>       {<br>          Logger logger = new Logger();<br>          logger.Error(&quot;Error occurred while calling    <br>                    GetCustomer() method. Error is:&quot;+ ex.Message)<br>       }<br>    }<br>}</pre><p>Above method is trying to get customers from database. but suppose some exception happened for whatever reason, catch block is trying to log the error for troubleshooting purpose.</p><p>This API call looks perfect, but there is a violation of SOLID principle. and that is : “S” : Single Responsibility principle. So single responsibility principle says: “<strong>A class or function should have single responsibility</strong>”. As per the name of method <strong>“GetCustomers” </strong>says “I am responsible for only getting the customers from somewhere, but i am not responsible for creating or initializing any object. Yes, i will of course log errors if there are any, if you provide me those object which are already been initialized.</p><p>It is same thing as the earlier example where you join a software company and ask your company to provide you a laptop, internet and other required things to proceed your work. You are responsible for performing a specific role for which you have been hired. Correct ?</p><p>In the same way when a class or function is created with some specific name, then it is only limited to perform only those specific functionality.</p><p>so the let’s modify the above code:</p><pre>public class CustomerController : ApiController<br>{<br><br>    [HttpGet]<br>    public IActionResult GetCustomers(Logger logger)<br>    {<br>       try  <br>       {<br>          .... code here for database call to get customers<br>       }<br>       catch(Exception ex)<br>       {<br>         logger.Error(&quot;Error occurred while calling    <br>                       GetCustomer() method. The Error is:&quot;+ ex.Message)<br>       }<br>    }<br>}</pre><p>Now above code obeys the “S” principle from SOLID principle. “<strong>GetCustomer</strong>” method is now only responsible for getting customer data from somewhere. Because whoever is calling the <strong>“GetCustomer”</strong> method, is passing the required dependency(that is logger object) in a function argument.</p><p>But let’s suppose if there are 100s of APIs in <strong>“CustomerController”</strong>, then every api method should get dependency in a parameter. So to avoid this complexity, .NET Core provides facility of injecting the dependencies into constructor of the class as follows:</p><pre>public class CustomerController : ApiController<br>{<br>    private Logger logger;<br><br>    public CustomerController(Logger _logger)<br>    {<br>        logger = _logger;<br>    }<br><br>    [HttpGet]<br>    public IActionResult GetCustomers()<br>    {<br>       try  <br>       {<br>          .... code here for database call to get customers<br>       }<br>       catch(Exception ex)<br>       {<br>         logger.Error(&quot;Error occurred while calling    <br>                       GetCustomer() method. The Error is:&quot;+ ex.Message)<br>       }<br>    }<br>    [HttpGet]<br>    public IActionResult GetCustomerById(int customerId)<br>    {<br>       try  <br>       {<br>          .... code here for database call to get customer by CustomerId<br>       }<br>       catch(Exception ex)<br>       {<br>         logger.Error(&quot;Error occurred while calling    <br>                       GetCustomerById() method. The Error is:&quot;+ ex.Message)<br>       }<br>    }<br>    <br>}</pre><p>Now above code <strong>“CustomerController”</strong> is getting injected with <strong>Logger</strong> object when the controller is initialized, so that each and every api method doesn’t need have a parameter with the <strong>Logger</strong> object. All api methods can use logger object which is initialized from constructor.</p><p>In order to to inject any dependencies into constructor of class, you have to register your dependencies (in this case dependency is Logger object) in ConfigureServices method of startup class of .NET Core project as follows:</p><pre>builder.Services.AddScopped&lt;Logger&gt;();</pre><p>In this blog i have tried to explain the basic fundamentals of Dependency injection that why we use it.</p><p>In order to know more about different dependency level you can read here:</p><p>“<a href="https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#service-lifetimes">https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#service-lifetimes</a>”</p><p>Hope you have basic idea about why and how we use dependency injection in .NET.</p><p>If you have any doubt, please feel free to drop any comment.</p><p>Thanks…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a2ece6aaecb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Delegates in C#]]></title>
            <link>https://medium.com/@ghanshyam.skipper/delegate-in-c-7d6f587c6092?source=rss-3cb194145e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d6f587c6092</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[delegate]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[dot-net-core]]></category>
            <dc:creator><![CDATA[Ghanshyam Thakkar]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 06:16:49 GMT</pubDate>
            <atom:updated>2022-01-27T12:49:48.913Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome technicians,</p><p>In this blog, I would like to share my knowledge on one of the C# Concept: Delegate in C#.</p><p><strong>What is Delegate in C#?</strong></p><p>A delegate is type that represent reference of function with parameters and a return type.</p><p>You might be confused reading at this definition of delegate. Lots of developer are not able to understand the delegate properly. In this blog we will understand delegate using proper C# program example.</p><p><strong>What is the use of delegate in C# ?</strong></p><p>You must be aware about passing parameter as int, float, string etc into method. These are datatypes that any method accepts as parameter. But did you ever heard passing whole method in the parameter ? Yes, you are right… we can pass whole method as value into method’s parameter.</p><p>So one question that must be arrive in our mind, that is , <strong>then what would be datatype in method parameter for another method</strong> ? So the answer is datatype is : <strong>delegate</strong>. so the answer for our titled question (what is the use of delegate) is <strong>delegate is used as a datatype for method </strong>(just like int, float, string….etc).</p><p>Let’s take a simple example:</p><pre>public string GetCustomerName(int customerId)<br>{<br>       some code...<br>       return customerName;<br>}</pre><p>In above function, I have a method : <strong>GetCustomerName </strong>having datatype as int. So you can pass any arbitrary value into parameter at the time of calling the method.</p><p>In the same way, in delegate once you define delegate as datatype you can pass arbitrary method as value in calling method. but how ?</p><p>Let’s take an example:</p><pre>using System;<br>namespace DelegateDemo<br>{<br>    class Program<br>    {<br>        public delegate void DelegateDisplay(string text);<br>        static void Main(string[] args)<br>        {<br>            var userInput = Console.ReadLine();</pre><pre>            Display(method1, userInput);</pre><pre>            Console.ReadLine();<br>        }<br>        public static void Display(DelegateDisplay del, string userInput)<br>        {<br>            del(userInput);<br>        }</pre><pre>        public static void method1(string name)<br>        {<br>            Console.WriteLine(&quot;You have entered :&quot;+ name);<br>        }<br>    }<br>}</pre><p>In above program, we are trying to get the input from user and print back to the console. First of all we have defined delegate named DelegateDisplayand we have Display method which accepts two arguments (1) delegate type (DelegateDisplay)(2) string type (userInput).</p><p>Now, when we run the program, we have to provide some input and press enter.</p><p>This line Display(method1, userInput); in the main method is very important, where we are just passing delegate type (i.e method1 ) and the input as a string (input provided by user).</p><p>method1 is whole method that we are passing into Display function. <strong>But make sure that we can only pass those method whose signature matches with the defined delegate (i.e input parameters and return type).</strong> In our case delegate DelegateDisplay has one input parameter string and return type is void. so we can pass any arbitrary method who has string input parameter and return type as void. and method1 exactly matches the signature required by delegate DelegateDisplay.</p><p>Now In Display method, we have called delegate : del(userInput); which is first parameter of the Display method. and we have passed method1 as a first parameter. So calling del(userInput); would look for reference attached to del(userInput); so method1 be called and it will accept the userInput entered in the console.</p><p>So this is what mean the definition explained in the beginning</p><blockquote>A delegate is type that represent reference of function with parameters and a return type</blockquote><blockquote>Now you must be thinking that why do use delegate when i can directly call Display ? it is very good question. so the answer is : Delegate is used, when we want to call a method from more than one methods dynamically. That means, Delegates is used, when we don’t know which method to run at compile-time (before running the program).</blockquote><p>So in our program, let’s say we have 5 methods, (method1, method2, method3, method4, and method5) and we want to call one method based on user input, and we have single point of calling method (Display) then based on user input, we can pass any of available 5 method into (Display ) method and call passed method.</p><p>So I hope, you understand the concept of delegate in C#. If you still have any confusion then please comment in this blog.</p><p>If you like this blog, then please clap for this blog.</p><p>Thank you…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d6f587c6092" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interface in C#]]></title>
            <link>https://medium.com/@ghanshyam.skipper/interfaces-in-c-6ea8d5037197?source=rss-3cb194145e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ea8d5037197</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[interfaces]]></category>
            <dc:creator><![CDATA[Ghanshyam Thakkar]]></dc:creator>
            <pubDate>Sun, 09 Jan 2022 15:35:37 GMT</pubDate>
            <atom:updated>2022-01-12T05:36:37.571Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome technicians,</p><p>In this blog I would like to share my knowledge on Interfaces in C#.</p><h3>What is Interface ?</h3><p>Interface is a common point where two system meet and interact.</p><p>Best example of interface would be: this website (medium.com), through which publisher share and subscriber gain the knowledge.</p><p>Interface is medium or connector through which peoples, systems, or organizations fulfill their purpose of work.</p><p>let’s see some real-time examples :</p><h4>(1) TV Screen</h4><p>TV screen is an interface where we can watch whichever channel is broadcasting. Again here two system are there (1) Watcher (2) Broadcaster. and interface is TV or Laptop screen.</p><h4><strong>(2)</strong> Brokers</h4><p>Brokers are one of the example of interface through which buyer buys and seller sells the product.</p><p>In the same way, in Programing, C# provides a way of interfacing between two entities through which entities can perform their purpose or work.</p><h4>Why we use Interface ?</h4><p>so one of the basic question come across our mind that <strong>why we need Interface ?</strong> so let me try to explain using simple example:</p><p>Suppose you want to display your laptop screen to TV screen, but your laptop doesn’t have HDMI port that connects to TV, but at anyhow you want to display laptop screen to TV and you do not have rights to install the HDMI port into laptop (because may be it’s your office’s laptop). So what would you do ? the answer is below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WHiUpYUh4CXAtkFfdy4DdQ.jpeg" /><figcaption>USB to HDMI Interface</figcaption></figure><p>Above image is the solution to your problem of displaying Laptop screen to TV screen, because you have USB port, so that you can use USB to HDMI Port cable to connect to TV screen. right?</p><p>yes you have got it right. Interface plays dual roles, interface knows the thing that one entity doesn’t know, and helps one entity to connect to second entity.</p><p>Let’s create a demo application to understand interfaces in C#.</p><p>Let’s suppose we have customer service, and this customer service provides data of customers to client.</p><p>So let’s create a simple console application and add another class library project named <strong>ServiceLibrary</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*IXQXWdqd3mIJpPthmHXJow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1g-52BAUSysSaNfK2lHrVg.png" /></figure><p>In first image, I have created <strong>serviceLibrary </strong>project in which I have three files</p><p>(1) Customer.cs (2) ICustomer.cs (3) Dependencies.cs</p><p>ICustomer.cs interface has two function defined. In customer.cs file, Customer class implements ICustomer Interface. So C# says, if you inherits interface, then you must implement all the methods of interface. so i have implemented both function inside customer class. Also one additional function is implemented inside customer class.</p><blockquote>In <strong>Dependecies.cs</strong> file, <strong>GetCustomerService</strong> function creates an instance of <strong>Customer </strong>class and returns from it. Here Customer object is assignable to ICustomer interface, <strong>this is the beauty of interface that holds class object whichever class inherits the interface</strong>.</blockquote><p>In this project console application(<strong>InterfaceDemo project</strong>) is client who is going to access the data of customer service. Now build the class library project and add reference to client (console application)</p><p>Now if you try to access the customerService class in the consoleApplication(<strong>InterfaceDemo project</strong>) then it would not be available because it is defined using internal modifier. this is the same problem as displaying laptop screen to TV without having HDMI cable access in Laptop.</p><p>so the solution is to use interface(<strong>ICustomer</strong>) to access the customer data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8OKOycdQfwNRe4ESLBwrQ.png" /></figure><p>So as per above image I can access the customerName and customerEmail using ICustomer.</p><p>You might be wondering that only two functions are accessible, but GetCustomerMobile is not accessible, because it is not defined inside the ICustomer interface. This is magic of interface, client can only access to those data whichever are defined into interface.</p><h4>Conclusion</h4><p>In Interface you can have only signatures of the functions. Interfaces can hold the object of class whichever class is inherit the interface. Whichever class inherit the interface must provide the implementation of all function available in interface.</p><p>I hope you understand the interfaces in C#.</p><p>If you like this blog then do clap for this post.</p><p>Thank you..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ea8d5037197" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Runtime Polymorphism in C#]]></title>
            <link>https://medium.com/@ghanshyam.skipper/runtime-polymorphism-in-c-8fbecce9cbb1?source=rss-3cb194145e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fbecce9cbb1</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[c-sharp-language]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Ghanshyam Thakkar]]></dc:creator>
            <pubDate>Sat, 08 Jan 2022 14:51:16 GMT</pubDate>
            <atom:updated>2022-01-08T14:51:16.481Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome technicians,</p><p>In this blog, I would like to share my knowledge on one of the basic OOPs concept : Polymorphism.</p><p>We will understand the concept of polymorphism by understanding with some real-time examples. Programming gets very easier if we map programming problems with real time situation.</p><h4><strong>What is Polymorphism?</strong></h4><p>Simple meaning of Polymorphism is: one name which have multiple forms.</p><p>If we explore the above meaning, we can say that any particular object is single but can play different roles.</p><p>Let’s consider below Realtime examples:</p><h4><strong>(1) Screwdriver :</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nDaJoJKfeugIQnGQi05vIg.jpeg" /></figure><p>As per the image above: you can see that there is only one handle but you can work with different types of screws using different types of tools by simply removing one and attaching another driver into handle.</p><h4>So you do not need to create a separate handle for each types of driver. The base is common but types are different.</h4><h4><strong>(2) ATM Machine</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*fTfJ-mju7CNM1zWg1gY7sA.jpeg" /></figure><p>If you ever used ATM machine, you know that, there is single machine inside which you can insert different types of different bank’s debit or credit cards and you can withdraw money. right ?</p><p><strong>So machine is single but it works for multiple bank’s credit or debit cards.</strong></p><p>Again in this example also, the base is common but types are different to get the work done.</p><p>In the same way, In OOPs programming, C# provides facility to create a common base and can attach different types into it to get work done.</p><p>Let’s create an example of Credit card system using polymorphism in C#.</p><p>let’s suppose we have credit card system where we have three different types of credit cards, (1) Platinum Credit card (2) Gold Credit card (3) Silver Credit card.</p><p>Just like ATM Machine, we are going to provide facility where we ask user to provide their input to know which type of credit card system user want to avail. If user enters input 1 then our program will return facility of Platinum credit card, if user enters input 2 then our program will return facility of Gold credit card, if user enters input 3then our program will return facility of Silver credit card,</p><p>Let’s create a simple base class called CreditCard and three different subclass as shown in below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eopo3wNqsI90-fYHgUKv-Q.png" /><figcaption>Credit Card System</figcaption></figure><p>In order to implement runtime polymorphism in C#, we have to define base class method as virtual, and sub-classes must have same method name and same number and type of parameters defined using override keyword.</p><p>In our case we have defined Purchase() method in base class (CreditCard class) and we have defined same method name: Purchase() in sub classes.</p><p>Now let’s ask user which credit card facility they want to avail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-md1MyWMJbtIwxXLcqL3fQ.png" /></figure><p>In above code, we are trying to get the user input at line no 15. Based on user we call and pass the input to GetCreditCard function.</p><p>Let’s suppose you have entered input : 1. So GetCreditCard function will instantiate the PlatinumCreditCard object and return to Main() method.</p><p>Now here the GetCreditCard Method has return type CreditCard (base class) and based on user input, one of the subclass object would be instantiated and assigns to CreditCard (base class) class. It is the same concept as screw driver where there is only one base handle but there are different sub driver you can attach to base handle. In our case CreditCard class is base handle where you can attach any subtype.</p><p>now let’s run this program and enter input : 1, So you have PlatinumCreditCard object in CreditCard class object.</p><p>At line no-19, we are trying to call the purchase() method, here creditcard object holds the type of platinum credit card so it will call the Purchase Method from Platinum creditcard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yJIuRlcMa4z3F_naTv1Kw.png" /><figcaption>credit card program execution.</figcaption></figure><p>Likewise you can enter different options from 1 to 3 to get different version of creditcard facility.</p><h3><strong>Conclusion</strong></h3><p>In Runtime polymorphism, we have one base handle, into which, we can attach different types of sub objects. Parent class is responsible for holding child class’s object (in which virtual method has been overridden) and calling the method of child class.</p><p>I hope you understand the concept of runtime polymorphism.</p><p>If you like this blog then please clap for this blog. Thank you…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fbecce9cbb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Access Modifiers in C#]]></title>
            <link>https://medium.com/@ghanshyam.skipper/access-modifiers-in-c-3c102bd0e0f7?source=rss-3cb194145e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c102bd0e0f7</guid>
            <category><![CDATA[c-sharp-language]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[c-sharp-concepts]]></category>
            <dc:creator><![CDATA[Ghanshyam Thakkar]]></dc:creator>
            <pubDate>Tue, 04 Jan 2022 08:25:17 GMT</pubDate>
            <atom:updated>2022-01-04T08:25:17.493Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome technicians…</p><p>In this blog, I would like to share my knowledge on Access Modifiers in C#.</p><h3><strong>What are Access Modifiers ?</strong></h3><p>Access Modifiers in C# are used to encapsulate our data.</p><p>In other words, we can say that, they are used to secure our data being accessed from outside. You can choose to define certain accessibility level of you data in C#.</p><p>There are five types of Access Modifiers in C#</p><p><strong>(1) Public</strong></p><p><strong>(2) Private</strong></p><p><strong>(3) Protected</strong></p><p><strong>(4) Internal</strong></p><p><strong>(5) Protected Internal</strong></p><p>let’s understand them one by one.</p><h3>(1) <strong>Public.</strong></h3><p>Any C# class, variable, property or function defined as a public can be accessible anywhere in the program using class object.</p><h3><strong>(2) Private</strong></h3><p>Class or class members defined using private are allowed to access only within the class where it is defined. It is not allowed anywhere in the program except inside the class.</p><p>For example: let’s consider following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eT0Z1Z5ZCPh3GFcBF4JOew.png" /></figure><p>In Above program, I am trying to access the variable counter inside <strong>SomeFunction()</strong> in same class, so it is allowed to access, but when I try to access variable counter (which is private variable) in other class (that is Order class) in <strong>SomeOtherFunction()</strong>, then it is not allowed to access using object.</p><h3>(3) Protected</h3><p>Class or class members defined using protected are accessible inside the same class and inside the child class. Protected members are not allowed to access using object anywhere in the program.</p><p>For example : let’s consider the following code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*FEM5214wFSUSGXyX1ormHA.png" /></figure><p>In Above Program, I have defined <strong>customerName </strong>variable<strong> </strong>using <strong>protected</strong> modifier, so it is allowed to access in it’s own class as well as in the child class. So you can see that <strong>customerName </strong>is accessible in <strong>Customer class </strong>as well as <strong>Order class. </strong>but it is not accessible any other places, so if you see in <strong>Purchase class, </strong>I am trying to access the<strong> customerName </strong>but it is not available to access.</p><h3>(4) Internal</h3><p>Internal Modifier is similar to public, but the only difference between public and internal modifier is that the internal modifier is allowed access inside the same assembly.</p><p>Here many developer assumes that assembly mean namespace, but this is not correct, <strong>actually the assembly is the current project where the internal modifier is defined</strong>. Assembly may contain more than one namespaces, so<strong> if you try to access internal modifier, which is defined in different namespace, is different but if they are in the same assembly (same project) then internal members are allowed to access in different assembly</strong>.</p><p>For example : let’s consider the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYR4pxb1n0cK_Ew5qMvzlQ.png" /></figure><p>In Above code, I have two files:<strong> (1) Customer.cs (2) Order.cs.</strong></p><p>In <strong>Customer.cs </strong>file, <strong>Customer class</strong> is defined using <strong>Customers </strong>namespace, and in<strong> Order.cs</strong> file, <strong>Order class</strong> is defined using <strong>CustomerOrders</strong> namespace. both namespace are different but they are in the same project, so internal modifier <strong>customerName</strong> is accessible inside the <strong>Order class.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d-9u0egs9-yl7Vyx4A5NOw.png" /></figure><p>In above Image, you can see, I have two Assembly(Project) in solution explorer, Assembly1 is <strong>BusinessLayer </strong>and Assembly2 is <strong>demo. </strong>I have defined internal variable <strong>customerName </strong>in <strong>customerBusiness.cs</strong> class in assembly1.</p><p>now let’s try to access <strong>customerName</strong> variable in Assembly2 (Demo Project)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*asoouETBfj4fw7CbylELxg.png" /></figure><p>you can see that customerName variable is no more accessible in assembly2 (Demo project).</p><h3>(4) Protected Internal</h3><p>Protected internal is same as Protected but the difference is that the protected internal is allowed to access in same class and in the child class but child class should be in the same assembly.</p><p>For example : let’s consider following code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZZTgI2ZU0triflCRpsSyA.png" /></figure><p>In above image, you can see that <strong>customerName </strong>variable is accessible inside the same class and child class. because both classes are in the same assembly (Project). but if you try to inherit <strong>customerBusiness </strong>class in another assembly(project), and try to access internal modifier in child class then it would not be accessible.</p><p>So I hope you have understand the Access Modifiers in C#.</p><p>If you like this blog then clap for this….</p><p>Thank you..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c102bd0e0f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Encapsulation in C#]]></title>
            <link>https://medium.com/@ghanshyam.skipper/encapsulation-in-c-6d1528cdae48?source=rss-3cb194145e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d1528cdae48</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Ghanshyam Thakkar]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 12:28:28 GMT</pubDate>
            <atom:updated>2021-12-12T12:28:28.715Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome Technicians,</p><p>In this blog, I would like to share my knowledge on one of the basic Pillar in OOPs.</p><h3><strong>What is Encapsulation ?</strong></h3><p>The action of enclosing something in. In other words, to protect something by enclosing.</p><p>When we say we encapsulate something, it mean we are protecting something from danger.</p><p>For example:</p><p>(1) Danger Animals in the prison:</p><p>We have seen danger animals in the prison in the zoo. why they are kept in prison ? The answer is, to protect humans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*63l5E3dqgENQDXUxRJ2zrA.jpeg" /><figcaption>Danger animals in the prison.</figcaption></figure><p>(2) Safe humans in the house:</p><p>We can say humans are safe and enclosed inside house in case of rain fall, snow fall, winter, high temperature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Ki0--_LiGnRIx1wloTGCtQ.jpeg" /><figcaption>Protected humans inside house.</figcaption></figure><p>(3) Electric switch board:</p><p>The switch board has enclosed all electric wires inside it. So any one can be protected from danger electric shot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75abxZo1a8NpT-YA-WpYnw.jpeg" /><figcaption>Electric wires inside switch board.</figcaption></figure><p>So as a conclusion of all above examples, we can say we are enclosing something to protect from danger.</p><p>In the same way, in programming language, there are some mechanism available where we can protect our data from danger.</p><p>In C#, we can enclose our data using some access modifier, so that data become safe from outside.</p><p>There are five access modifier level, using which, we can protect our data</p><p>(1) Internal</p><p>(2) Public</p><p>(3) Private</p><p>(4) Protected</p><p>(5) Protected Internal</p><p>for example:</p><p>public class ABC</p><p>{</p><p>private int counter = 10;</p><p>public int Counter{</p><p>get{ return counter;}</p><p>}</p><p>}</p><p>In Above example, we have declare counter variable using private access modifier, and we have provided public property named : Counter.</p><p>So nobody would be able to set the value of variable counter from outside.</p><p>This is called Encapsulation. we have enclosed our variable counter using private access modifier, so anybody outsider can read the value of variable but can not set the value of counter variable.</p><p>let me give you real time example:</p><p>If you go to any restaurant, you can see Menu Card, in which, you can only read the price of items available in the restaurant, but you can not change them. right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*yhtGA_lvq1lBiAS2uyWHww.jpeg" /></figure><p>Thank you…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d1528cdae48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Abstraction in C#]]></title>
            <link>https://medium.com/@ghanshyam.skipper/abstraction-in-c-aa0c38d887dd?source=rss-3cb194145e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa0c38d887dd</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <dc:creator><![CDATA[Ghanshyam Thakkar]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 11:28:41 GMT</pubDate>
            <atom:updated>2021-12-12T11:28:41.113Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome Technicians,</p><p>In this blog, I would like to share my knowledge on one of the pillars of OOPs. So let’s get started.</p><p><strong>What is Abstraction?</strong></p><p>Abstraction is dealing with ideas rather than concrete realities.</p><p>For example -</p><p>(1) Engine inside Car.</p><p>Once you look at the car, you can imagine or you can say that there would be an engine in the car. The engine is not visible, but it is there in the car.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*--isWCIcP1LRihmX" /></figure><p>(2) Wires in the wall —</p><p>Any house or building have electric wires hidden inside the wall. what if wires are not hidden in the house? how much complexity you have to manage with your living inside house ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*6fWQwi7Q9RkuFxuB" /></figure><p>(3) Circuits inside TV or Laptop :</p><p>If you ever have seen inside any electronics device, there must have electronic circuits hidden inside instrument, why those circuits are hidden from operator ? the answer is to hide or remove the complexity. right ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*1TEB0xId_Br-mxCV" /></figure><p>(4) Operating System in Computer:</p><p>As you know, when the computer was invented, there was no operating system before, only DOS system was working behind computer. so if you want to create any file, open file, save file, or for any other operation, you must have to write and execute command. but using operating system, you do not have to worry about writing and executing any command and you only just work with nice graphical user interface and mouse click to do any work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*TV7fsY-ydD5IUWim" /></figure><p>So as a conclusion of all above examples is to hide the complexity and use flexibility.</p><p>In the same way, in programming, by looking at some inbuilt method you can imagine that there would be some code (implementation) inside the method, but code is made invisible for the developer in order to hide complexity and make system flexible.</p><p>For example — look at the below code:</p><p>static void Main(string[] args)</p><p>{</p><p>int counter = 10;</p><p>string str = counter .ToString();</p><p>}</p><p>In the above example, when you try to access the method counter.ToString(), you can imagine that Microsoft must have written some code while implementing the ToString() method to convert the value into a string type. This is called Abstraction. you can imagine the things which are made invisible for the purpose of reducing complexity.</p><p>In the above example, microsoft has implemented abstraction for developer, but as a developer you can also implement abstraction in your own application in order to hide complexity in your project.</p><p>For Example : DLLs is one of the example for implementing abstraction.</p><p>When you import any DLL, you can see only signatures of the function, but you can not see implementation of those method, you don’t have to worry about what would be implementation in order to call those methods containing DLLs.</p><p>Other ways of Implementing Abstraction:</p><p>(1) Using Abstract Class.</p><p>(2) Using Interfaces.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa0c38d887dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>