<?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 Pramod Shivaprasad on Medium]]></title>
        <description><![CDATA[Stories by Pramod Shivaprasad on Medium]]></description>
        <link>https://medium.com/@pramod2392?source=rss-be46851bc871------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*vgOsASRkUDipni_U</url>
            <title>Stories by Pramod Shivaprasad on Medium</title>
            <link>https://medium.com/@pramod2392?source=rss-be46851bc871------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:28:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pramod2392/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[Pessimistic Concurreny method]]></title>
            <link>https://medium.com/@pramod2392/pessimistic-concurreny-method-8028cfd8a8cd?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/8028cfd8a8cd</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Mon, 09 Nov 2026 19:17:50 GMT</pubDate>
            <atom:updated>2026-11-09T19:17:50.740Z</atom:updated>
            <content:encoded><![CDATA[<p>A way to handle “Check-then-update” race condition</p><p>In the previous blog, we have discussed about “Check-then-update” race condition. Here is the link to that blog <a href="https://medium.com/@pramod2392/check-then-update-race-condition-bdba97bcfe82">https://medium.com/@pramod2392/check-then-update-race-condition-bdba97bcfe82</a></p><p>In this blog, let’s look at the “pessimistic concurrency” method to handle the “Check-then-update” race condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZMQIDNasQG7U8d9EAPSOng.png" /></figure><p>In this method, we lock the rows while we fetch them from db for checking the condition and release the lock only after updating the database. Meanwhile if any other request tries to fetch the same row, then it will have to wait until the other request unlocks it.</p><p>Let’s look at the below code snippet and observe the changes made</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L1RlQ8V70lks8ptXTRZbaA.png" /></figure><ol><li>Instead of fetching all the rows using (_teamContext.Tasks.FirstOrDefaultAsync()) we are using raw sql with “FOR UPDATE” clause.<br>“<em>In SQL, the </em><strong><em>FOR UPDATE</em></strong><em> clause is a concurrency control mechanism appended to a </em><em>SELECT statement to implement </em><strong><em>row-level locking</em></strong><em>. It reads the requested rows and locks them until the current transaction is finished (either via </em><em>COMMIT or </em><em>ROLLBACK), preventing other concurrent transactions from modifying or deleting that specific data in the meantime.</em>”</li><li>We have enclosed the entire “check-then-update” code snippet within the transaction block</li></ol><p>Let’s do the same concurrent test for the updated code with the help of postman to see if the scenario is handled.</p><p>We have simulated 3 concurrent users invoking the api for 1 minute</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*epdT8eJklUfoQKluFeg40g.png" /></figure><p>Notice from the below screenshot that now as expected only one api call succeeds and all other 93 requests fail. So we are abe to handle the “check-then-update” race condition with these changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y80VYU3rKE2XhfsPixKiLQ.png" /></figure><p>Let’s compare the difference in the performance of the api with the existing code(code with race condition) and with the pessimistic concurrency method of solving the race condition.</p><p>Code with race condition took around 1.09 s (Note code has a explicit delay of 1s to simulate some operation) as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xssS047qKG8Velk7BPeKJg.png" /></figure><p>Code with pessimistic concurrency method of handling race condition took around 1.43 s (Note code has a explicit delay of 1s to simulate some operation)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ibeRlqdVHP5kXwtH18PIA.png" /></figure><p>From above comparison we see there is a bit of performance hit with the Pessimistic concurrency method of handling race condition.</p><p>In this article we have discussed about the Pessimistic concurrency method for handling the race condition. In the upcoming blog, I will discuss about other methods to handle the race condition.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8028cfd8a8cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Check-then-update race condition]]></title>
            <link>https://medium.com/@pramod2392/check-then-update-race-condition-bdba97bcfe82?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdba97bcfe82</guid>
            <category><![CDATA[entity-framework-core]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[csharp-programming]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 18:54:46 GMT</pubDate>
            <atom:updated>2026-11-08T18:54:46.316Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog let’s discuss about the “Check-then-update” race condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VUpXWxlWu-e6C9_rtwvGwg.png" /></figure><p>Consider the scenario where we have a project and a technical team. The team lead publishes the tasks. Based on the area of expertise and interest, the team members will assign the task to themselves.</p><p>Look at the below snippet of code which performs assignment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N62zQxju1Q3u_jMZZ6fCZA.png" /></figure><ol><li>The code snippet first tries to fetch the task with given id from db and checks if task with given id is present and also whether the task is in unassigned state.</li><li>If the task with given Id is not present or task is already in assigned state, then it returns false which in turn returns Bad Request response.</li><li>If the task is present and is in unassigned state then it assigns the task to the caller.</li><li>Updates the detail in the database</li></ol><p>The above code looks good and works fine. Do you agree or do you see any issues with this? Let’s find out below!</p><p>Consider the team is huge with about 250 employees with multiple leads.<br>When a team lead publishes a task, there is a chance more than one employee tries to assign it to himself concurrently. We will try to simulate this scenario below.</p><p>We will try to re-create this scenario using postman.<br>Let’s invoke this api from postman using “Run Collection” option as shown below with 3 virtual users for 1 minute duration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nyMkfB5T8W-cyjFVBQ9nrQ.png" /></figure><p>Below are the results</p><p>Total 170 requests were made in 1 minute by 3 users.</p><p>Notice that 167 requests failed with Bad Request error and 3 requests got the success response!!</p><p>Ideally our expectation is only 1 request should receive success response and all other requests should get Bad request. Because after the first successful request, the task would already be in assigned state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJlXqEmpLavvX2lgoQaIag.png" /></figure><p>This illustrates the check-then-update race condition.</p><p>Let’s look at the code snippet again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*N62zQxju1Q3u_jMZZ6fCZA.png" /></figure><p>Since multiple team members can try to assign the task to themselves concurrenty, consider two team memebrs try to assign concurrently.</p><p>What happens is Request 1(R1) made by User1(U1) fetches the task from db and finds that task exists and it is in unassiged state (Line 26–27). R1 continues executing further statements. Before R1 assigns the task to U1 and updates the db (Line 34–36), Request (R2) made by User2(U2) fetches the task from db and finds that the task exsists and it is in unassigned state. So R2 also continues executing further statements. So both U1 &amp; U2 receive success response. But the task would be assigned to U2 who made request R2 after request R1. R1 changes would be overwritten by R2.</p><p>In this blog, we have discussed about the “check-then-update” race condition and when can it happen. In the next blog, we will discuss about the different techniques that we can use to handle this race condition.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdba97bcfe82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WPF Button control]]></title>
            <link>https://medium.com/@pramod2392/wpf-button-control-12564598c3cd?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/12564598c3cd</guid>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Sat, 08 Aug 2026 22:00:30 GMT</pubDate>
            <atom:updated>2026-08-08T22:00:30.490Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, let’s discuss about the WPF button control which is defined in “System.Windows.Controls” namespace</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XUm2n8sjkbnR-mPmx0aHfA.png" /></figure><p>As we all know the basic feature supported by the button is a click event. The click event supports three modes. These modes define when the click event will trigger.</p><p>The three modes are</p><ol><li>Hover</li><li>On Click</li><li>On release after click (default behavior)</li></ol><p><strong>Hover : </strong>The click event is triggered when user hovers the cursor on the button.</p><p><strong>On Click : </strong>The click event is triggered when user clicks on the button.</p><p><strong>On Release : </strong>The click event is triggered when user clicks and releases the cursor on the button. This is the default behavior. If the user clicks on the button but doesn’t release while the cursor is on the button, then the event is not triggered.</p><p>WPF (MainWindow.xaml)</p><pre>&lt;Window x:Class=&quot;LearnWPF.MainWindow&quot;<br>        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br>        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br>        xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;<br>        xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;<br>        xmlns:local=&quot;clr-namespace:LearnWPF&quot;<br>        mc:Ignorable=&quot;d&quot;<br>        Title=&quot;MainWindow&quot; Height=&quot;450&quot; Width=&quot;800&quot;&gt;<br>    &lt;Grid&gt;<br>        &lt;Grid.RowDefinitions&gt;<br>            &lt;RowDefinition/&gt;<br>            &lt;RowDefinition/&gt;<br>            &lt;RowDefinition/&gt;<br>            &lt;RowDefinition/&gt;<br>        &lt;/Grid.RowDefinitions&gt;<br>        &lt;Grid.ColumnDefinitions&gt;<br>            &lt;ColumnDefinition/&gt;<br>            &lt;ColumnDefinition/&gt;<br>            &lt;ColumnDefinition/&gt;<br>        &lt;/Grid.ColumnDefinitions&gt;<br>        &lt;Button Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot; ClickMode=&quot;Hover&quot; Name=&quot;HoverButton&quot; Click=&quot;HoverButton_Click&quot; Content=&quot;Hover me&quot;&gt;&lt;/Button&gt;<br>        &lt;Button Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot; ClickMode=&quot;Press&quot; Name=&quot;PressButton&quot; Click=&quot;PressButton_Click&quot; Content=&quot;Press me&quot;&gt;&lt;/Button&gt;<br>        &lt;Button Grid.Row=&quot;2&quot; Grid.Column=&quot;0&quot; ClickMode=&quot;Release&quot; Name=&quot;ReleaseButton&quot; Click=&quot;ReleaseButton_Click&quot; Content=&quot;Click and release on me&quot;&gt;&lt;/Button&gt;<br>        &lt;Button Grid.Row=&quot;3&quot; Grid.Column=&quot;0&quot; Name=&quot;DefaultButton&quot; Click=&quot;DefaultButton_Click&quot; Content=&quot;Default button&quot;&gt;&lt;/Button&gt;<br>    &lt;/Grid&gt;<br>&lt;/Window&gt;</pre><p>(MainWindow.xaml.cs)</p><pre>using System.Drawing;<br>using System.Text;<br>using System.Windows;<br>using System.Windows.Controls;<br>using System.Windows.Data;<br>using System.Windows.Documents;<br>using System.Windows.Input;<br>using System.Windows.Media;<br>using System.Windows.Media.Imaging;<br>using System.Windows.Navigation;<br>using System.Windows.Shapes;<br><br>namespace LearnWPF<br>{<br>    /// &lt;summary&gt;<br>    /// Interaction logic for MainWindow.xaml<br>    /// &lt;/summary&gt;<br>    public partial class MainWindow : Window<br>    {<br>        public MainWindow()<br>        {<br>            InitializeComponent();<br>        }<br><br>        private void HoverButton_Click(object sender, RoutedEventArgs e)<br>        {<br>            Button button = sender as Button;<br>            button.Background = System.Windows.Media.Brushes.Blue;<br>        }<br><br>        private void PressButton_Click(object sender, RoutedEventArgs e)<br>        {<br>            Button button = sender as Button;<br>            button.Background = System.Windows.Media.Brushes.Blue;<br>        }<br><br>        private void ReleaseButton_Click(object sender, RoutedEventArgs e)<br>        {<br>            Button button = sender as Button;<br>            button.Background = System.Windows.Media.Brushes.Blue;<br>        }<br><br>        private void DefaultButton_Click(object sender, RoutedEventArgs e)<br>        {<br>            Button button = sender as Button;<br>            button.Background = System.Windows.Media.Brushes.Blue;<br>        }<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12564598c3cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference between Transient and Scoped service lifetimes in DI in .NET core]]></title>
            <link>https://medium.com/@pramod2392/difference-between-transient-and-scoped-service-lifetimes-in-di-in-net-core-6c8820c17621?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c8820c17621</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 19:08:03 GMT</pubDate>
            <atom:updated>2026-06-25T19:08:03.158Z</atom:updated>
            <content:encoded><![CDATA[<p>As you all know, .NET has built in dependency injection since the initial version of .NET core.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pIt5MpoHL597H2Hm.jpg" /></figure><p>Dependency injection in .NET core supports three service lifetimes</p><ol><li>Singleton : Single instance of the service is used across the application</li><li>Scoped : A separate instance is created per HTTP request or for every new scope</li><li>Transient : A new instance is created every time the service is requested.</li></ol><p>The Singleton and Transient service lifetimes are a bit easier to understand from the definition. But the scoped is somewhat difficult to understand for someone hearing it for the first time or someone new to .NET.</p><p>I will try to exaplain the difference between them in this article. I got the clarity on the scoped service lifetime recently.</p><p>I will be using WPF application</p><p>I will give a brief on the application setup.</p><ol><li>Application targets “net10.0-windows” version.</li><li>WPF application doesn’t come with inbuilt configuration for enabling DI, so I have added the required configuration to setup DI in WPF application.</li><li>Added two xaml window to show the difference between transient and scoped.</li></ol><p>You can refer below microsoft document to setup DI in WPF <br><a href="https://learn.microsoft.com/en-us/dotnet/desktop/wpf/app-development/how-to-use-host-builder">https://learn.microsoft.com/en-us/dotnet/desktop/wpf/app-development/how-to-use-host-builder</a></p><p>Below are the two screens created.</p><p><strong>MainWindow.xaml</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oX-HzKxCFhAB2HtI44QQKQ.png" /></figure><p>On click of Details button, it shows the details window and hides the current window.</p><p><strong>DetailsWindow.xaml</strong><br>On click of Back button it shows the MainWindow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SV7CpCWvWxJZn7Zb-NN8RQ.png" /></figure><p>Basically this is all I have in this application.</p><p>Now let’s look at the behaviour of Transient and Scoped lifetimes</p><p>The DI is configured in app.xaml as below</p><p>I am injecting both DetailsWindow and MainWindow as <strong><em>transient</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_zG4CzA50XIdN3m6-ITyQ.png" /></figure><p>I am receiving the dependencies via Constructor as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yUs9gZDWmzOCWueeoDCA-w.png" /></figure><p>Now, let’s run the application, MainWindow loads as shown below. I have enterd values for FirstName and LastName. I will click on Details button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*czDvbcWZ3dzJRRk2XgzD8w.png" /></figure><p>Clicking on Details button, loads the Details window and hides the current window as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XcHalzLw6sE4vq2TtnIv8Q.png" /></figure><p>I will just click on Back button without making any other actions. The current window is hidden and the MainWindow is shown as shown below</p><p>Notice that both FirstName and LastName textboxes are empty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Bf7NCqv4GucJvhk4WyWrA.png" /></figure><p>Now let me update the DI configuration in app.xaml to be scoped</p><p>I am injecting both DetailsWindow and MainWindow as <strong><em>scoped </em></strong>now as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b7EO4guTKNysatmL4JQhAw.png" /></figure><p>Let’s launch the application and re-iterate the same steps</p><p>MainWindow loads as shown below. I have entered the details. I will click on Details button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpbS63cbHBXECjVqbC-zIw.png" /></figure><p>The DetailsWindow will be shown and the current window is hidden as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5_L6c3-9uNrG-xgDXtTK0A.png" /></figure><p>I will click on Back button which will load the MainWindow and hide the current window as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5KPVGUApAZk6TxySYPGeQ.png" /></figure><p>Notice that now the previously entered values “Rahul” and “Dravid” are retained. This shows the difference between Transient and Scoped service lifetime.</p><p>On click of “Details” button, the code responsible for showing the MainWindow is shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*C2ecSec5W073oOq10gQStg.png" /></figure><p>To further demonstrate scope lifetime, let me change the back button click implementation to as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PWWCiBDKlEx36_T_0UarFA.png" /></figure><p>Let’s re-iterate the steps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4XjXTZHifDrKVktlg6axQ.png" /></figure><p>On click of Details button, it shows the Details screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XN9MvA1hP2VPa3FCMn9XGA.png" /></figure><p>Click of back button, shows the Main window. Notice that first name and last name fields are empty. We created a new scope and then displayed the MainWindow, this led to creation of new instance of MainWindow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ne2U1bShUllStnXzpYJQjQ.png" /></figure><p>When service lifetime is kept as “Transient”, in our app, whenever we show the MainWindow, it creates a new instance of MainWindow which will not retain any previous values.</p><p>But when we keep service lifetime as “Scoped”, in our app, within the same scope how much ever time we show the MainWindow it will return the same instance of the MainWindow which will retain the previous values.</p><p>If we create a new scope, then a new instance is created and the values are not retained as seen before.</p><p>Hope this article was informative and helpful. Let me know your thoughts in the comments section. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c8820c17621" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building and managing your knowledge portfolio]]></title>
            <link>https://medium.com/@pramod2392/building-and-managing-your-knowledge-portfolio-cd4126cd2a47?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd4126cd2a47</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[coders]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programmer]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Mon, 20 Apr 2026 15:42:05 GMT</pubDate>
            <atom:updated>2026-04-20T15:42:05.974Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog content is completely from the book “The Pragmatic Programmer”</p><p>I have been reading the 20th anniversary edition of the book “The Pragmatic Programmer” which is written by “David Thomas” and “Andrew Hunt”. I am really liking this book, I have found many short topics which are invaluable! Topics are crystal clear and easy to understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*83D1SjoFCBL21cK92oQ4qQ.jpeg" /></figure><p>I came across the topic on knowledge portfolio in the book. I find it helpful and thought of sharing it here.</p><p>Knowledge Portfolio of a software engineer includes below items</p><ol><li>All the facts, programmers (software engineers) know about computing</li><li>The application domains they work in</li><li>All their experience</li></ol><p>Managing a knowledge portfolio is very similar to managing a financial portfolio.</p><ol><li>Serious investors invest regularly — as a habit</li><li>Diversification is the key to long term success</li><li>Smart investors balance their portfolios between conservative and high-risk, high-reward investments.</li><li>Investors try to buy low and sell high for maximum return.</li><li>Portfolios should be reviewed and rebalanced periodically</li></ol><p>To be successful in your career, you must invest in your knowledge portfolio using these same guidelines.</p><p>The good news is that managing this kind of investment is a skill just like any other, it can be learned. The trick is to make yourself do it initially and form a habbit. Develop a routine which you follow until your brain internalizes it. At that point, you will find yourself sucking up new knowledge automatically.</p><p>Steps to build your portfolio</p><ol><li>Invest regularly<br>Just as in financial investing, you must invest in your knowledge portfolio regularly, even if it’s just a small amount. The habit is as important as the sums, so plan to use a consistent time and place, away from interruptions</li><li>Diversify<br>The more different things you know, the more valuable you are. <br>As a baseline, you need to know the ins and outs of the particular technology you are working with currently. But don’t stop there. <br>The face of computing changes rapidly — hot technology today may well be close to useless (or atleast not in demand) tomorrow. <br>The more technologies you are comfortable with , the better you will be able to adjust to change. <br>Don’t forget all the other skills you need, including those in non-technical areas.</li><li>Manage risk<br>Technology exists along a spectrum from risky, potentially high-reward to low-risk, low-reward standards. It’s not a good idea to invest all of your money in high-risk stocks that might collapse suddenly, nor should you invest all of it conservatively and miss out on possible opportunities. Don’t put all your technical eggs in one basket.</li><li>Buy low, sell high<br>Learning an emerging technology before it becomes popular can be just as hard as finding an undervalued stock, but the payoff can be just as rewarding. <br>Learning Java back when it was first introduced and unknown may have been risky at the time, but it paid off handsomely for the early adopters when it became an industry mainstay later</li><li>Review and rebalance<br>This is very dynamic industry. That hot technology you started investing last month might be stone cold by now. Maybe you need to brush up on that database technology that you haven’t used in a while. Or perhaps you could be better positioned for that new job opening if you tried out that other language</li></ol><p>Of all these guidelines, the most important one is the simplest to do:<br>“<strong>Invest Regularly in Your Knowledge Portfolio</strong>”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd4126cd2a47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Squares of a sorted array]]></title>
            <link>https://medium.com/@pramod2392/squares-of-a-sorted-array-c7cb2d23edbd?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7cb2d23edbd</guid>
            <category><![CDATA[sorting]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[arrays]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Sun, 01 Mar 2026 11:25:19 GMT</pubDate>
            <atom:updated>2026-03-01T11:25:19.148Z</atom:updated>
            <content:encoded><![CDATA[<p>Given an integer array nums sorted in <strong>non-decreasing</strong> order, return <em>an array of </em><strong><em>the squares of each number</em></strong><em> sorted in non-decreasing order</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XGLBICDU2W0MB5uqKLXCfg.png" /></figure><p>Example 1</p><pre>Input: nums = [-4,-1,0,3,10]<br>Output: [0,1,9,16,100]<br>Explanation: After squaring, the array becomes [16,1,0,9,100].<br>After sorting, it becomes [0,1,9,16,100].</pre><p>Example 2</p><pre>Input: nums = [-7,-3,2,3,11]<br>Output: [4,9,9,49,121]</pre><p>Constraints</p><ul><li>1 &lt;= nums.length &lt;= 10000</li><li>-10000 &lt;= nums[i] &lt;= 10000</li><li>nums is sorted in <strong>non-decreasing</strong> order.</li></ul><p>Explaination</p><p>The ask is simple<br>1. Input is an integer array<br>2. We need to square each element of input array and assign it to an output array<br>3. Then we need to sort the items of the output array in non-decreasing (ascending) order<br>4. Return the array</p><p><strong>Approach 1</strong></p><p>The straight forward approach is to<br>1. Create an output integer array of same length<br>2. Iterate through the items of the input array, sqaure the item and assign the squared value to output array<br>3. Return the output</p><pre>public class Solution {<br>    public int[] SortedSquares(int[] nums) {<br>        int[] output = new int[nums.Length];<br>        int i = 0;<br>        foreach(int num in nums){   // O(n)<br>            output[i] = num * num;<br>            i++;<br>        }<br>        <br>        output.Sort();  // O(nlogn)<br>        return output;<br>    }<br>}</pre><p>If we look at the complexity of the above code, it would be O(n) + O(nlogn) ==&gt; O(nlogn)</p><p><strong>Note: </strong>The input is already in non-decreasing order, we need the output in the same non-decreasing order. We need to sort the elements only because we have negative values in the input.<br>If the input contains only non-negative items in non-decreasing order, then the output will be by default in non-decreasing order without the need for sorting.</p><p>Example</p><p>Input : 0, 2, 4, 7, 9</p><p>Output: 0, 4, 16, 49, 81</p><p><strong>Approach 2</strong></p><p>Let’s look at the more optimized O(n) solution for the problem</p><p>To understand this approach, let’s look at example input and output</p><p>Examples</p><p>Input: nums = [<strong>-7</strong>, -3, 2, 3, <strong>11</strong>]<br>Output: [4, 9, 9, 49, <strong>121</strong>]</p><p>Input: nums = [<strong>-10</strong>, -4, 0, 2, <strong>9</strong>]<br>Output: [0, 4, 16, 81, <strong>100</strong>]</p><p>Since the input is in non-descending order, either the leftmost or the rightmost item contribute to the last element of the output array as they are the highest.</p><p>In the first example, [<strong>-7</strong>, -3, 2, 3, <strong>11</strong>], <br>LeftPointer = -7<br>RightPointer = 11</p><p>Abs(RightPointer) &gt; Abs(LeftPointer) → So the last element of the output array will be (11 * 11) = 121. output[4] = 121</p><p>Now compare the Leftmost with last but one in the rightmost<br>LeftPointer = -7<br>RightPointer = 3</p><p>Abs(LeftPointer) &gt; Abs(RightPointer) → So the last but one element of the output array will be (-7 * -7) = 49. output[3] = 49</p><p>In this way we can find all the elements of the output array.</p><pre>public class Solution {<br>    public int[] SortedSquares(int[] nums) {<br>        int length = nums.Length;<br>        int leftPointer = 0;<br>        int rightPointer = length - 1;<br>        int[] output = new int[length];<br>        int outputPointer = length - 1;<br><br>        while(leftPointer &lt;= rightPointer)   // O(n)<br>        {<br>            if(Math.Abs(nums[leftPointer]) &gt; Math.Abs(nums[rightPointer]))<br>            {<br>                output[outputPointer] = nums[leftPointer] * nums[leftPointer];<br>                outputPointer--;<br>                leftPointer++;<br>            }<br>            else<br>            {<br>                output[outputPointer] = nums[rightPointer] * nums[rightPointer];<br>                outputPointer--;<br>                rightPointer--;<br>            }<br>        }<br><br>        return output;<br>    }<br>}</pre><p>If we look at the complexity of this approach,<br>Here we iterate through all the items of the array once which contributes to O(n). We don’t have to perform Sort(), so the overall complexity would be O(n)</p><p>Let me your thoughts about the trivial and the O(n) approach. Do you have a different or a better approach towards this problem? Let me know in the comments section. Thanks..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7cb2d23edbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Problem on arrays(Max Consecutive Ones)]]></title>
            <link>https://medium.com/@pramod2392/problem-on-arrays-max-consecutive-ones-5c78d055fa23?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c78d055fa23</guid>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[csharp-programming]]></category>
            <category><![CDATA[arrays]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 13:41:26 GMT</pubDate>
            <atom:updated>2026-02-12T13:41:26.382Z</atom:updated>
            <content:encoded><![CDATA[<p>Max Consecutive Ones</p><p>In the coding interviews our approach towards solving the programming challenge is as important as solving the challenge itself. A well-structured approach is key to solving the problem efficiently within the given timeframe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8rtM3HQpZbv_M3biNg20A.png" /></figure><p>In this article, I will explain my approach towards this programming challenge and how I updated it to make it a perfect solution</p><p><strong>Challenge:</strong></p><p>Given a binary array nums, return the maximum number of consecutive 1’s in the array.</p><p><strong>Constraints:</strong></p><p>1 &lt;= nums.length &lt;= 105<br>nums[i] is either 0 or 1.</p><p><strong>Example 1:</strong></p><p>Input: nums = [1,1,0,<strong>1,1,1</strong>]<br>Output: 3<br>Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.</p><p><strong>Example 2:</strong></p><p>Input: nums = [1,0,<strong>1,1</strong>,0,1]<br>Output: 2</p><p>Approach:</p><p>1. Create an integer variable to keep track of the number of 1s (<strong>consecutiveCount</strong>)</p><p>2. Iterate through each items of the array. If the item is 1, then increment the variable <strong>consecutiveCount</strong> by 1. If the item is 0, then set the variable <strong>consecutiveCount</strong> to 0</p><p>3. Return the <strong>consecutiveCount</strong></p><p>My initial code</p><pre>public class Solution {<br>    public int FindMaxConsecutiveOnes(int[] nums) {<br>        int consecutiveCount = 0;<br>        foreach(int num in nums){<br>            if(num == 1){<br>                consecutiveCount++;<br>            }<br>            else{                <br>                consecutiveCount = 0;<br>            }                                <br>        }<br>        <br>        return consecutiveCount;<br>    }<br>}</pre><p>The above code failed for the below test case<br>1, 1, 1, 0, 1, 1<br><strong>Expected Output</strong> : 3<br><strong>Actual Output </strong>: 2<br>I realized I am looking for the consecutivecount but not the maximum of that. After we get “0”(4th element in the input array) the “consecutivecount” is set to 0. Then there are two 1&#39;s after that so the code returns the output as 2</p><p>I updated the code to use “maxConsecutiveCount”</p><pre>public class Solution {<br>    public int FindMaxConsecutiveOnes(int[] nums) {<br>        int consecutiveCount = 0;<br>        int maxConsecutiveCount = 0;<br>        foreach(int num in nums){<br>            if(num == 1){<br>                consecutiveCount++;<br>            }<br>            else{<br>                if(consecutiveCount &gt; maxConsecutiveCount){<br>                    maxConsecutiveCount = consecutiveCount;<br>                }<br>                consecutiveCount = 0;<br>            }                                <br>        }<br>        <br>        return maxConsecutiveCount;<br>    }<br>}</pre><p>Here I have a variable to hold the maxConsecutiveCount. I check to see if the consecutiveCount is greater than maxConsecutiveCount, if yes, then I assign consecutiveCount to maxConsecutiveCount. So that the maxConsecutiveCount always has the maximum value.</p><p>The above code fails for below scenario<br>1, 0, 1, 0, 1, 1, 1<br><strong>Actual Output</strong>: 1<br><strong>Expected Output</strong>: 3<br>Only else block has the condition to check for the max.</p><p>I updated the code again</p><pre>public class Solution {<br>    public int FindMaxConsecutiveOnes(int[] nums) {<br>        int consecutiveCount = 0;<br>        int maxConsecutiveCount = 0;<br>        foreach(int num in nums){<br>            if(num == 1){<br>                consecutiveCount++;<br>            }<br>            else{<br>                if(consecutiveCount &gt; maxConsecutiveCount){<br>                    maxConsecutiveCount = consecutiveCount;<br>                }<br>                consecutiveCount = 0;<br>            }                                <br>        }<br>        <br>        if(consecutiveCount &gt; maxConsecutiveCount){<br>            maxConsecutiveCount = consecutiveCount;<br>        }<br>        <br>        return maxConsecutiveCount;<br>    }<br>}</pre><p>The above code passed all the test cases.</p><p>As you see, I started writing code thinking this is a very simple problem and was expecting to solve it in one attempt. But I had missed many scenarios. It required multiple attempts to finally arrive at the solution.</p><p>Understanding the problem clearly and practising more such problems will definitely improve our approach. Let me know your thoughts and your approach in the comments section. See you in the next article. Till then take care bye..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c78d055fa23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transition from backend developer to full stack developer]]></title>
            <link>https://medium.com/@pramod2392/transition-from-backend-developer-to-full-stack-developer-08f6e98d7ee1?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/08f6e98d7ee1</guid>
            <category><![CDATA[back-end-developer]]></category>
            <category><![CDATA[full-stack-developer]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Sun, 01 Feb 2026 14:38:33 GMT</pubDate>
            <atom:updated>2026-02-01T14:38:33.063Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*YX3r93dKc2hOra8RwEZjgg.webp" /></figure><p>I am an Advanced software developer with expertise in C#, .NET core and azure cloud technologies. In the initial years of my career I have worked with HTML, CSS and JavaScript. I can only say I have worked but I don’t really know much about UI development. My focus has been to improve my skills in the backend development all these years. It still continues to be my focus.</p><p>Having said that I wanted to start understanding and learn few concepts in UI. I wanted to try a different way and make this learning more interesting. I want to just pick an activity and try to achieve it. I will share my findings and understanding here. I wish to connect with others with similar interests and make this journey more entertaining.</p><p>As you all might agree, building and running an application locally is a trivial thing to know. I wanted to try building and running our UI code.</p><p>In our project we use react based web UI.</p><ol><li>I started with cloning the UI code from github repo.</li><li>Opened the UI code in visual studio</li></ol><p>I asked github copilot on how I can build and run the code locally</p><p>3. I had to install Node.js v24.12.0 (LTS) from official website (<a href="https://nodejs.org/en/download">https://nodejs.org/en/download</a>) I downloaded the windows installer.</p><p>4. I tried below commands to verify the installation<br>“<em>npm — version</em>” and “<em>node — version</em>”</p><p>5. Then I had to install all the referenced packages with the help of below command “<em>npm install</em>”</p><p>6. Then tried to build and run the application using “<em>npm start</em>”</p><p>7. I got errors related to some missing packages and I had to run below command to install them forcibly despite version mismatch<br>“<em>npm install — legacy-peer-deps</em>”</p><p>8. I tried again to build and run the application. I got the error as “<strong>scuf packages are returning 404 errors</strong>”</p><p>9. “<strong>Scuf</strong>” package was a new word for me! Upon google search I got to know “Scuf” packages are the private packages that can be hosted on a private npm registry</p><p>10. Then by looking at the github workflow file, copilot got to know the urls from which the scuf packages can be downloaded.</p><p>11. Copilot created a <strong>.npmrc</strong> file and added all the scuff package urls to it.</p><p>.npmrc file is a configuration file for the npm that stores settings like</p><ol><li>Auth tokens</li><li>Proxy settings</li><li>Package installation preferences</li></ol><p>12. After creating .npmrc file, and tried “npm start”, Hurray!! build got completed successfully!!</p><p>My application launched in google chrome..</p><p>With this activity, I got to know about steps in building a react web app. Got to know about <strong>scuf pacakges</strong>, <strong>.npmrc file</strong>. Hope this helps.</p><p>In the next article I will come up with another activity and detail about my findings.</p><p>Happy to connect with others with similar interests. Try similar activity and let me know about your experience. Feel free to suggest me different activity that I should try in the comments section. I will be happy to explore.</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08f6e98d7ee1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solve the programming question using Events in C#]]></title>
            <link>https://medium.com/@pramod2392/solve-the-programming-question-using-events-in-c-22452e31c35e?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/22452e31c35e</guid>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Wed, 29 Oct 2025 13:21:29 GMT</pubDate>
            <atom:updated>2025-10-29T13:21:29.888Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s understand events through a simple programming question.</p><p>Here is the question</p><p>“In a C# console application, create a method which takes array of string as input parameter. The method has to check if the strings are palindrome and raise an event for each string if it is palindrome. Main method needs to listen to the event and print the event message”</p><p>In my previous blog we saw how to solve this question using delegates in c#<br><a href="https://medium.com/@pramod2392/solve-the-programming-question-using-delegates-in-c-af9e409a8659">https://medium.com/@pramod2392/solve-the-programming-question-using-delegates-in-c-af9e409a8659</a></p><p>Let’s see how to solve this using Events in c#</p><p>Similar to delegate approach,</p><p>We will create the new class “PalindromeChecker.cs” which would contain the method “CheckIsPalindrome”.<br>The “CheckIsPalindrome” method has to accept string array as input parameter. The method has to iterate over the string array and check if each string is palindrome. If the string is palindrome then it has to notify interested subscribers.</p><h3>Events Approach:</h3><p>PalindromeChecker.cs</p><pre>using System.Text;<br><br>namespace EventsDemo<br>{<br>    public class PalindromeChecker<br>    {<br>        public event EventHandler&lt;string&gt; OnPalindromeEvent = delegate { };<br>        public void IsPalindrome(string[] inputArray)<br>        {<br>            foreach (string input in inputArray)<br>            {<br>                string reverseString = Reverse(input);<br>                if (string.Equals(input, reverseString))<br>                {<br>                    OnPalindromeEvent(this, $&quot;The string {input} is a palindrome&quot;);<br>                } <br>            }<br>        }<br><br>        private string Reverse(string input)<br>        {<br>            char[] inputArray = input.ToCharArray();<br>            int length = inputArray.Length;<br>            StringBuilder sb = new StringBuilder();<br><br>            for (int i = length - 1; i &gt;= 0; i--)<br>            {<br>                sb.Append(inputArray[i]);<br>            }<br>            return sb.ToString();<br>        }<br>    }<br>}</pre><p>As shown in the code snippet above, we have defined an event of type EventHandler&lt;string&gt;. Here the generic type we have used is of type string, since we just want to send string data from publisher to subscribers.</p><p>EventHandler&lt;T&gt; is a generic delegate which can point to methods which accpet two input parameters. First one of type object and second of type &lt;T&gt; and the method returns void.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4DVQCtvbQv1madvtpOjXLA.png" /></figure><p>Program.cs</p><pre>namespace EventsDemo<br>{<br>    internal class Program<br>    {<br>        static void Main(string[] args)<br>        {<br>            Console.WriteLine(&quot;Enter input strings separated by comma&quot;);<br>            string[]? inputArray = Console.ReadLine()?.Split(&quot;,&quot;);<br><br>            if(inputArray == null || inputArray.Length == 0)<br>            {<br>                Console.WriteLine(&quot;Restart the application and provide non empty string input&quot;);<br>                return;<br>            }<br><br>            PalindromeChecker stringOperations = new PalindromeChecker();<br>            stringOperations.OnPalindromeEvent += StringOperations_OnPalindromeEvent;<br><br>            stringOperations.IsPalindrome(inputArray);<br>        }<br><br>        private static void StringOperations_OnPalindromeEvent(object? sender, string e)<br>        {<br>            Console.WriteLine(e);<br>        }<br>    }<br>}</pre><p>As shown in the code snippet above,</p><ol><li>Program.cs contains the code to request and read the input data.</li><li>Then we create an instance of PalindromeChecker class and call the “CheckIsPalindrome” method by passing the input string array.</li><li>Before calling the “CheckIsPalindrome” method we have also subscribed to the “OnPalindromeEvent” exposed by PalindromeChecker class</li><li>“StringOperations_OnPalindromeEvent” method is the event handler. It accepts two input parameters. One of type “Object” and the other of type a string as input parameters. It writes the input string to the console.<br>Notice the signature of the “StringOperations_OnPalindromeEvent” method matches with the EventHandler&lt;string&gt; delegate of PalindromeChecker class.</li></ol><pre>PalindromeChecker stringOperations = new PalindromeChecker();<br>stringOperations.OnPalindromeEvent += StringOperations_OnPalindromeEvent;</pre><p>When we run the application and pass the input strings, we get below output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*osQM6OFdPLgRtKqbsBs5eg.png" /></figure><p>In this article we have seen how to raise events from publisher class and how to listen to those event as a subscriber. Let me know your thoughts in the comments section. In the next article let’s discuss on the difference between events and delegates.</p><p>Thanks for reading. I will be back with the next article soon..</p><p>Until then bye, take care!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22452e31c35e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solve the programming question using delegates in C#]]></title>
            <link>https://medium.com/@pramod2392/solve-the-programming-question-using-delegates-in-c-af9e409a8659?source=rss-be46851bc871------2</link>
            <guid isPermaLink="false">https://medium.com/p/af9e409a8659</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[delegates-in-csharp]]></category>
            <dc:creator><![CDATA[Pramod Shivaprasad]]></dc:creator>
            <pubDate>Mon, 27 Oct 2025 10:10:06 GMT</pubDate>
            <atom:updated>2025-10-27T10:14:19.060Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s understand delegates through a simple programming question</p><p>Here is the question<br><br>“In a C# console application, create a method which takes array of string as input parameter. The method has to check if the strings are palindrome and raise an event for each string if it is palindrome. Main method needs to listen to the event and print the event message”</p><p>To solve this problem, we will create a new class which would contain a method which would perform the required action.</p><p>We will create the new class “PalindromeChecker.cs” which would contain the method “CheckIsPalindrome”.<br>The “CheckIsPalindrome” method has to accept string array as input parameter. The method has to iterate over the string array and check if each string is palindrome. If the string is palindrome then it has to notify interested subscribers.</p><h3>Delegate approach</h3><p>PalindromeChecker.cs</p><pre>using System.Text;<br><br>namespace InterviewQuestionOnEvents<br>{<br>    public class PalindromeChecker<br>    {<br>        public Action&lt;string&gt; IsPalindromeEvent = delegate { };<br>        <br>        public void CheckIsPalindrome(string[] inputStrings)<br>        {<br>            int stringLength = inputStrings.Length;<br><br>            for(int i = 0; i &lt; stringLength; i++)<br>            { <br>                string input = inputStrings[i].ToUpper();<br>                string reverseString = ReverseString(input);<br>                if (string.Equals(input, reverseString))<br>                {<br>                    IsPalindromeEvent.Invoke($&quot;The string {inputStrings[i]} is palindrome&quot;);                    <br>                }<br>                <br>            }<br>        }<br><br>        private string ReverseString(string input)<br>        {<br>            StringBuilder stringBuilder = new StringBuilder();<br>            char[] charStrings = input.ToCharArray();<br>            int charLength = charStrings.Length;<br><br>            for (int i = charLength - 1; i &gt;= 0; i--)<br>            {<br>                stringBuilder.Append(charStrings[i]);<br>            }<br><br>            return stringBuilder.ToString();<br>        }<br>    }<br>}</pre><p>As shown in the code snippet above, we have defined a generic action delegate with the return type of string.</p><pre>public Action&lt;string&gt; IsPalindromeEvent = delegate { };</pre><p>Private “ReverseString” method contains the logic to reverse the given string.<br>If the string is palindrome we call invoke method of the action delegate “IsPalindromeEvent”</p><p>Program.cs</p><pre>namespace InterviewQuestionOnEvents<br>{<br>    internal class Program<br>    {<br>        static void Main(string[] args)<br>        {<br>            Console.WriteLine(&quot;Enter strings separated by commma&quot;);<br>            string[]? inputStrings = Console.ReadLine()?.Split(&quot;,&quot;);<br>            if (inputStrings == null)<br>            {<br>                Console.WriteLine(&quot;Please re-run the application and enter strings in comma separated format&quot;);<br>            }<br><br>            /*Using a method*/<br><br>            #region using a separate method<br><br>            PalindromeChecker checker = new PalindromeChecker();<br>            checker.IsPalindromeEvent += PrintToConsole;<br><br>            #endregion method<br><br>            checker.CheckIsPalindrome(inputStrings);            <br><br>            Console.ReadLine();<br>        }<br><br>        public static void PrintToConsole(string inputString)<br>        {<br>            Console.WriteLine(&quot;&quot;);<br>            Console.WriteLine(&quot;From PrintToConsole method&quot;);<br>            Console.WriteLine(inputString);<br>        }<br>    }<br>}</pre><p>As shown in the code snippet above,</p><ol><li>Program.cs contains the code to request and read the input data.</li><li>Then we create an instance of PalindromeChecker class and call the “CheckIsPalindrome” method by passing the input string array.</li><li>Before calling the “CheckIsPalindrome” method we have also hooked our PrintToConsole method to “IsPalindromeEvent”</li><li>“PrintToConsole” method accepts a string as input parameter. It writes the input string to the console.<br>Notice the signature of the “PrintToConsole” method matches with the Action delegate “IsPalindromeEvent” of PalindromeChecker class.</li></ol><pre>checker.IsPalindromeEvent += PrintToConsole;</pre><p>What the above code snippet does is, whenever the Invoke method of the IsPalindromeEvent is invoked from “PalindromeChecker.cs” class then the “PrintToConsole” method will also be invoked.</p><p>When we run the application and pass the input strings, we get below output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*wPCzXFnW60FdfUnSSmw7_w.png" /></figure><p>In the above “Program.cs” code we created a separate method “PrintToConsole” which will be executed when the palindrome event is raised.</p><p>Let’s look at other possible options than creating a new method.</p><ul><li>Using lambda expression.<br>We can use lambda expression here instead of creating a separate method.</li></ul><pre>namespace InterviewQuestionOnEvents<br>{<br>    internal class Program<br>    {<br>        static void Main(string[] args)<br>        {<br>            Console.WriteLine(&quot;Enter strings separated by commma&quot;);<br>            string[]? inputStrings = Console.ReadLine()?.Split(&quot;,&quot;);<br>            if (inputStrings == null)<br>            {<br>                Console.WriteLine(&quot;Please re-run the application and enter strings in comma separated format&quot;);<br>            }<br>            <br>            PalindromeChecker checker = new PalindromeChecker();<br><br>            #region using lambda expression<br><br>            checker.IsPalindromeEvent += (string input) =&gt;<br>            {<br>                Console.WriteLine(&quot;&quot;);<br>                Console.WriteLine(&quot;Using lambda expression&quot;);<br>                Console.WriteLine(input);<br>            };<br><br>            #endregion using lambda expression            <br><br>            checker.CheckIsPalindrome(inputStrings);            <br><br>            Console.ReadLine();<br>        }<br>    }<br>}</pre><p>Notice above that we don’t have separate “PrintToConsole” method.<br>Rather we have similar implementation using lambda expression</p><pre>checker.IsPalindromeEvent += (string input) =&gt;<br>            {<br>                Console.WriteLine(&quot;&quot;);<br>                Console.WriteLine(&quot;Using lambda expression&quot;);<br>                Console.WriteLine(input);<br>            };</pre><p>When we run the application and provide same input as before, we get similar results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*ieBDlcs1clrDfGlGfXxFow.png" /></figure><ul><li>Using Anonynous method<br>Another approach is to use anonynous method. Instead of lambda expression we can use anonymous methods too.</li></ul><pre>namespace InterviewQuestionOnEvents<br>{<br>    internal class Program<br>    {<br>        static void Main(string[] args)<br>        {<br>            Console.WriteLine(&quot;Enter strings separated by commma&quot;);<br>            string[]? inputStrings = Console.ReadLine()?.Split(&quot;,&quot;);<br>            if (inputStrings == null)<br>            {<br>                Console.WriteLine(&quot;Please re-run the application and enter strings in comma separated format&quot;);<br>            }<br><br>            <br>            PalindromeChecker checker = new PalindromeChecker();<br><br>            #region using anonymous method<br><br>            checker.IsPalindromeEvent += delegate (string input)<br>            {<br>                Console.WriteLine(&quot;Using anonymous method&quot;);<br>                Console.WriteLine(input);<br>            };<br><br>            #endregion using anonymous method<br><br>            checker.CheckIsPalindrome(inputStrings);            <br><br>            Console.ReadLine();<br>        }<br>    }<br>}</pre><p>In the above code snippet, we have used anonymous method instead of lambda expression.</p><pre>checker.IsPalindromeEvent += delegate (string input)<br>            {<br>                Console.WriteLine(&quot;Using anonymous method&quot;);<br>                Console.WriteLine(input);<br>            };</pre><p>When we run the application and provide same input as before, we get similar results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*vC_fkdJj-ejv07UngCvN0A.png" /></figure><p>In this article we understood how to implement callback methods in c# using delegates. We have discussed the different ways to hook up with the delegate “Separate method”, “Lambda expression”, “Anonymous method”<br>In the next article we will understand how to achieve similar results using Events in C#</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af9e409a8659" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>