<?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 Sarada Devi Yerubandi on Medium]]></title>
        <description><![CDATA[Stories by Sarada Devi Yerubandi on Medium]]></description>
        <link>https://medium.com/@saradadeviyerubandi?source=rss-5143f057cc5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wuu2m8nGhrbymKTRQCBWTQ.jpeg</url>
            <title>Stories by Sarada Devi Yerubandi on Medium</title>
            <link>https://medium.com/@saradadeviyerubandi?source=rss-5143f057cc5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:52:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saradadeviyerubandi/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[Role of Luhn Algorithm in Validating Credit Card Numbers]]></title>
            <link>https://medium.com/@saradadeviyerubandi/role-of-luhn-algorithm-in-validating-credit-card-numbers-5551ac42a5b7?source=rss-5143f057cc5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5551ac42a5b7</guid>
            <dc:creator><![CDATA[Sarada Devi Yerubandi]]></dc:creator>
            <pubDate>Thu, 07 Nov 2024 15:27:26 GMT</pubDate>
            <atom:updated>2024-11-07T15:27:26.381Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how credit card numbers get validated in the backend? Meet the Luhn Algorithm, one of the most widely used methods for quickly checking if a credit card number is valid. This algorithm, simple yet powerful, helps ensure accuracy in countless transactions every day.</p><h4>What is Luhn Algorithm?</h4><blockquote>The Luhn Algorithm, sometimes known as the ‘modulus 10’ algorithm, is a simple checksum formula that helps detect errors in numbers. Developed by IBM scientist Hans Peter Luhn in the 1950s, it’s widely used to validate identification numbers, especially credit card numbers. What makes it so effective is that it can quickly catch simple errors, like mistyped or transposed digits, helping prevent invalid entries from going through.</blockquote><h4><em>So, how does the Luhn algorithm actually work? Let’s break it down into three simple steps:</em></h4><ol><li>Starting from the rightmost digit, double every second digit. If the result of any doubling operation is greater than nine, then add the digits of the result together to obtain a single-digit number. (Example: 2<em>×</em>6=12; 1+2=3).</li><li>Find the sum of all the digits that you didn’t double and the new values that you got from doubling.</li><li>Determine if the total sum is a multiple of ten. According to the Luhn algorithm, the number is considered to be valid if the total ends in zero.</li></ol><p>To give you an illustration, let’s verify the number 79927398713 using the Luhn algorithm formula.</p><p>Start from the right and double every second digit:</p><p>Original number: 7<strong> 9</strong> 9 <strong>2</strong> 7<strong> 3</strong> 9 <strong>8</strong> 7 <strong>1</strong> 3</p><p>Doubling every second digit:</p><p>1 <em>× </em>2 = 2</p><p>8 <em>× </em>2 = 16 (1 + 6 = 7)</p><p>3 <em>× </em>2 = 6</p><p>2 <em>× </em>2 = 4</p><p>9 x 2 = 18 (1 + 8 = 9)</p><p>Calculate sum of all the digits, including the undoubled digits:</p><p>7 + 9 + 9 + 4 + 7 + 6 + 9 + 7 + 7 + 2 + 3 = 70</p><p>The number 79927398713 is valid according to the Luhn algorithm because the result is 70, which is a multiple of 10.</p><p>Here is the C# code snippet for example:</p><pre>using System.Text.RegularExpressions;<br><br>class Program<br>{<br>    public static void Main()<br>    {<br>        string cardNo = &quot;79927398713&quot;;<br><br>        bool result = isValidLuhn(cardNo);<br>        if (result)<br>        {<br>            Console.WriteLine(&quot;Valid credit card&quot;);<br>        }<br>        else<br>        {<br>            Console.WriteLine(&quot;Invalid credit card&quot;);<br>        }<br>    }<br><br>    private static bool isValidLuhn(string cardNo)<br>    {<br>        try<br>        {<br>            //removing any white spaces in the given credit card number<br>            string validatedCardNo = Regex.Replace(cardNo, @&quot;\s&quot;, &quot;&quot;);<br>            int sum = 0;<br>            //initially second digit is set to false<br>            bool isSecondDigit = false;<br>            for(int i = validatedCardNo.Length - 1; i &gt;= 0; i--)<br>            {<br>                //converting digit from char to integer<br>                int digit = int.Parse(validatedCardNo[i].ToString());<br>                if (isSecondDigit)<br>                {<br>                    digit = digit * 2;<br>                    if (digit &gt; 9)<br>                    {<br>                        digit = (digit/10) + (digit%10);<br>                    }<br>                }<br>                sum += digit;<br>                //here we are toggling the second digit boolean<br>                isSecondDigit = !isSecondDigit;<br>            }<br>            return (sum % 10 == 0);<br>        }<br>        catch<br>        {<br>            throw new Exception();<br>        }<br>    }<br>}</pre><h4>What kind of numbers does the Luhn Algorithm validates?</h4><p>In any system where numbers are entered manually, the Luhn algorithm can serve as a real-time validation tool to instantly detect and highlight errors, thereby improving data quality and operational efficiency.</p><p>Examples: Credit Card Numbers, IMEI numbers for mobile numbers,Banks use the Luhn algorithm to verify account numbers and other financial identifiers before processing transactions.</p><h4>Luhn Algorithm Limitations</h4><p>While the Luhn algorithm is a powerful tool for error detection and numerical validation, it has certain limitations. In the context of fraud detection or comprehensive data validation, the Luhn algorithm is typically just one component of a broader set of checks and balances. Relying on it solely for these purposes is not advisable.</p><p><strong>Complex Error Detection</strong>: The Luhn algorithm is effective at catching common errors, such as single-digit mistakes or adjacent digit transpositions (e.g., 67 becoming 76). However, it cannot detect more complex errors, such as non-adjacent digit swaps (e.g., 791 becoming 917).</p><p><strong>Fraud Detection</strong>: While the Luhn algorithm can verify that a sequence of numbers is potentially valid, it cannot confirm whether it corresponds to a legitimate account or identity. It is also not effective against deliberate fraudulent activities, where the fraudster uses a valid number sequence.</p><p><strong>Non-Numeric Data</strong>: The algorithm applies only to numeric data and cannot validate sequences that include letters, symbols, or other non-numeric characters.</p><p><strong>Data Integrity</strong>: The Luhn algorithm checks numerical validity but does not assess data integrity. It cannot detect intentional data alterations or identify which specific part of the data is incorrect.</p><p><strong>Predictability</strong>: As a well-known and widely used algorithm, the Luhn algorithm is predictable. Anyone with knowledge of the algorithm can generate numbers that pass the Luhn check, which can be a disadvantage in scenarios requiring high levels of security.</p><p>Despite its limitations, the Luhn algorithm remains a widely used tool for performing preliminary checks on numerical sequences, particularly in financial services.</p><p>I hope this blog helped you understand the Luhn Algorithm. Thanks for reading, and happy learning! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5551ac42a5b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C# interview preparation-01]]></title>
            <link>https://medium.com/@saradadeviyerubandi/c-interview-preparation-01-ec5ebb6db8c6?source=rss-5143f057cc5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec5ebb6db8c6</guid>
            <dc:creator><![CDATA[Sarada Devi Yerubandi]]></dc:creator>
            <pubDate>Sun, 06 Oct 2024 15:01:46 GMT</pubDate>
            <atom:updated>2024-11-05T14:23:03.582Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone! In today’s blog, I’ll be sharing couple of basic questions that came up during a recent interview for a Senior .NET Developer position. Though we might feel confident and easy to explain about these types of questions, it’s crucial to be clear with our answers during an interview. Let’s get into the questions now.</p><h4>1. Can we create instance of an interface and an abstract class?</h4><p>No, we cannot create an instance of either an interface or an abstract class directly in C#. Both are meant to be used as blueprints for other classes, rather than to be instantiated themselves.</p><blockquote>Interfaces define a contract (methods, properties, events) without providing any implementation. A class that implements the interface must provide concrete implementations for the interface members.</blockquote><pre>    internal interface IFriends<br>    {<br>        void GetFriendsList();<br>    }<br><br>    internal class Friends : IFriends<br>    {<br>        public void GetFriendsList()<br>        {<br>            Console.WriteLine(&quot;Chandler\nMonika\nRoss\nRachel\nJoey\nPhoebe&quot;);<br>        }<br>        public static void Main()<br>        {<br>            //IFriends friends = new IFriends();  // Not allowed!<br>            IFriends friends = new Friends();  // Allowed<br>            friends.GetFriendsList();<br>        }<br>    }</pre><blockquote>Abstract classes can have both abstract methods (which must be implemented by derived classes) and fully implemented methods. However, they cannot be instantiated directly.</blockquote><pre><br>    public abstract class Friends<br>    {<br>        public abstract void GetFriendsList();<br>    }<br><br>    public class Program : Friends<br>    {<br>        public override void GetFriendsList()<br>        {<br>            Console.WriteLine(&quot;Chandler\nMonika\nRoss\nRachel\nJoey\nPhoebe&quot;);<br>        }<br>        public static void Main()<br>        {<br>            //Friends friends = new Friends();  // Not allowed!<br>            Friends friends = new Program();  // Allowed<br>            friends.GetFriendsList();<br>        }<br>    }</pre><p>To use either, you must create a subclass (in the case of an abstract class) or implement the interface in a concrete class, then instantiate that class.</p><h4>2. What is partial class in c#?</h4><p>A partial class in C# allows you to split a class definition into multiple files. This feature is especially useful when dealing with large classes. All parts of the partial class are combined by the compiler into a single class when the application is compiled.</p><p>The partial keyword is what makes this possible. By adding partial before the class declaration, you are telling the compiler that the class is defined across multiple files. However, all the parts of a partial class must be within the same namespace.</p><h4>Why Use Partial Classes?</h4><p>Partial classes are useful in several scenarios:</p><ol><li><strong>Separation of Concerns</strong>: You can organize code better by separating logically related parts into different files.</li><li><strong>Collaboration</strong>: When working in a team, multiple developers can work on different parts of the class simultaneously without dealing with merge conflicts.</li></ol><h4>Example of a Partial Class in C#</h4><p>Let’s consider a simple Person class split across two files. This example shows how we can separate property definitions and methods into different files while still working with the same class.</p><blockquote>File 1: PersonOne.cs</blockquote><pre>    public partial class Person<br>    {<br>        public string FirstName { get; set; }<br>        public string LastName { get; set; }<br><br>        public void DisplayFullName()<br>        {<br>            Console.WriteLine($&quot;{FirstName} {LastName}&quot;);<br>        }<br>    }</pre><p>In this file, we have defined part of the Person class, including two properties: FirstName and LastName, as well as a method DisplayFullName() that prints the full name of the person.</p><blockquote>File 2: PersonTwo.cs</blockquote><pre>    public partial class Person<br>    {<br>        public int Age { get; set; }<br><br>        public void DisplayAge()<br>        {<br>            Console.WriteLine($&quot;Age: {Age}&quot;);<br>        }<br>    }</pre><p>In the second file, we have defined the Age property and a method DisplayAge() that prints the age of the person.</p><h4>How to Use the Partial Class</h4><p>Here’s how we can use the Person class defined across multiple files:</p><pre>    class Program<br>    {<br>        public static void Main()<br>        {<br>            Person person = new Person();<br>            person.FirstName = &quot;Sarada Devi&quot;;<br>            person.LastName = &quot;Yerubandi&quot;;<br>            person.Age = 24;<br><br>            person.DisplayFullName();  // Output: Sarada Devi Yerubandi<br>            person.DisplayAge(); //Output: Age: 24<br>        }<br>    }</pre><p>In the above example, even though the Person class is split into two files, the compiler combines them at compile time, so the person object can access members from both files seamlessly.</p><p><strong>Key Points to Remember</strong></p><ul><li>All parts of a partial class must be in the same namespace.</li><li>You can have multiple partial class files, but the compiler will combine them into a single class.</li><li>A partial class can also be spread across multiple projects, as long as the projects are in the same solution and namespace.</li><li>Partial classes can also have partial methods, which are methods that are defined in one part of the class and optionally implemented in another.</li><li>For smaller classes, partial classes might not be necessary and can even make the code harder to follow. It’s essential to use this feature when it makes sense.</li></ul><p>I hope this post helped clarifying the questions:</p><ol><li>Can we create instance of an interface and an abstract class?</li><li>What is Partial class in C#?</li></ol><p>Let me know your reviews in the comment section. Thanks for reading. Happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec5ebb6db8c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C# Interface Conflicts: How to Handle Same Method Names in Multiple Interfaces]]></title>
            <link>https://medium.com/@saradadeviyerubandi/c-interface-conflicts-how-to-handle-same-method-names-in-multiple-interfaces-a8ef6b706995?source=rss-5143f057cc5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8ef6b706995</guid>
            <dc:creator><![CDATA[Sarada Devi Yerubandi]]></dc:creator>
            <pubDate>Sun, 29 Sep 2024 15:13:26 GMT</pubDate>
            <atom:updated>2024-09-29T15:13:26.063Z</atom:updated>
            <content:encoded><![CDATA[<p>In C#, interfaces are powerful tools that allow developers to define contracts that classes can implement. But what happens when you implement multiple interfaces that contain methods with the same name and signature? This is where E<strong>xplicit Interface Implementation</strong> becomes essential.</p><p>This article will explain how to handle method name conflicts when implementing multiple interfaces, and how to leverage explicit interface implementation to resolve these conflicts.</p><p><strong>Problem: Method Name Conflicts in Interfaces</strong></p><p>Suppose you have two interfaces, IFirstInterface and ISecondInterface, both containing a method with the same signature. You want a single class, MyClass, to implement both interfaces but provide distinct implementations for each interface&#39;s method.</p><p>Here’s what that might look like:</p><pre>interface IFirstInterface<br>{<br>    void CommonMethod();<br>}<br><br>interface ISecondInterface<br>{<br>    void CommonMethod();<br>}</pre><p>At first glance, this can lead to a potential conflict. Without explicit interface implementation, there is no way for the class to distinguish between the two methods. Here’s how you can handle this problem.</p><h4>Solution: Explicit Interface Implementation</h4><p>The key to resolving method name conflicts is <strong>explicit interface implementation</strong>. By explicitly implementing the methods, you can specify which method belongs to which interface, thereby avoiding ambiguity.</p><p>Let’s look at an example where a class implements both interfaces:</p><pre>class MyClass : IFirstInterface, ISecondInterface<br>{<br>    // Explicit interface implementation for IFirstInterface<br>    void IFirstInterface.CommonMethod()<br>    {<br>        Console.WriteLine(&quot;Method implementation from IFirstInterface.&quot;);<br>    }<br><br>    // Explicit interface implementation for ISecondInterface<br>    void ISecondInterface.CommonMethod()<br>    {<br>        Console.WriteLine(&quot;Method implementation from ISecondInterface.&quot;);<br>    }<br>}</pre><h4>Explanation:</h4><ol><li><strong>Explicit Interface Implementation</strong>: Each method is prefixed by the interface it belongs to (IFirstInterface or ISecondInterface). This tells the C# compiler which interface’s method is being implemented.</li><li><strong>Method Accessibility</strong>: With explicit interface implementation, the methods can only be accessed through an interface reference. You won’t be able to call these methods directly from an instance of MyClass.</li></ol><h4>Accessing Explicitly Implemented Methods</h4><p>Since these methods are explicitly implemented, they cannot be accessed directly through an instance of MyClass. Instead, you need to cast the object to the specific interface before calling the methods.</p><p>Let’s see how this works in the Main() method:</p><pre>class MyClass : IFirstInterface, ISecondInterface<br>{<br>    // Explicit interface implementation for IFirstInterface<br>    void IFirstInterface.CommonMethod()<br>    {<br>        Console.WriteLine(&quot;Method implementation from IFirstInterface.&quot;);<br>    }<br><br>    // Explicit interface implementation for ISecondInterface<br>    void ISecondInterface.CommonMethod()<br>    {<br>        Console.WriteLine(&quot;Method implementation from ISecondInterface.&quot;);<br>    }<br>}<br>class Program<br>{<br>    static void Main(string[] args)<br>    {<br>        MyClass obj = new MyClass();<br><br>        // Accessing IFirstInterface&#39;s Method<br>        IFirstInterface first = obj;<br>        first.CommonMethod();  // Output: Method implementation from IFirstInterface.<br><br>        // Accessing ISecondInterface&#39;s Method<br>        ISecondInterface second = obj;<br>        second.CommonMethod();  // Output: Method implementation from ISecondInterface.<br>    }<br>}</pre><h4>Key Points:</h4><ul><li><strong>Casting to Interface</strong>: In the above example, obj is cast to IFirstInterface and ISecondInterface to access their respective CommonMethod() implementations. Without this cast, calling CommonMethod() on obj directly would result in a compile-time error because the methods are explicitly implemented and not accessible from the class instance.</li><li><strong>Explicit Control</strong>: Explicit interface implementation allows you to fully control how the class behaves when implementing multiple interfaces with the same method names. It ensures that you provide a distinct implementation for each interface’s version of the method.</li></ul><h4>When to Use Explicit Interface Implementation</h4><p>Explicit interface implementation is particularly useful when:</p><ul><li>Two or more interfaces have methods with identical signatures, and you want to provide distinct implementations.</li><li>You want to keep interface methods hidden from the class’s public API, only making them accessible via the interface reference.</li></ul><h4>Final Thoughts</h4><p>Explicit interface implementation is a powerful feature in C# that helps resolve method name conflicts when implementing multiple interfaces. By using this technique, you can ensure that each interface’s methods are implemented separately, without ambiguity or conflict. This keeps your code clean, readable, and free from potential method collision issues.</p><p>Mastering this concept is crucial for handling complex scenarios where multiple interfaces share method names, and it empowers you to write more flexible and maintainable C# code.</p><h4>Summary Code Snippet</h4><p>Here’s a quick recap of how explicit interface implementation can be applied:</p><pre><br>interface IFirstInterface<br>{<br>    void CommonMethod();<br>}<br><br>interface ISecondInterface<br>{<br>    void CommonMethod();<br>}<br>class MyClass : IFirstInterface, ISecondInterface<br>{<br>    // Explicit interface implementation for IFirstInterface<br>    void IFirstInterface.CommonMethod()<br>    {<br>        Console.WriteLine(&quot;Method implementation from IFirstInterface.&quot;);<br>    }<br><br>    // Explicit interface implementation for ISecondInterface<br>    void ISecondInterface.CommonMethod()<br>    {<br>        Console.WriteLine(&quot;Method implementation from ISecondInterface.&quot;);<br>    }<br>}<br>class Program<br>{<br>    static void Main(string[] args)<br>    {<br>        MyClass obj = new MyClass();<br><br>        // Accessing IFirstInterface&#39;s Method<br>        IFirstInterface first = obj;<br>        first.CommonMethod();  // Output: Method implementation from IFirstInterface.<br><br>        // Accessing ISecondInterface&#39;s Method<br>        ISecondInterface second = obj;<br>        second.CommonMethod();  // Output: Method implementation from ISecondInterface.<br>    }<br>}</pre><p>By understanding and applying explicit interface implementation, you can manage method conflicts with ease and write better C# code.</p><p>Thanks for reading! Happy learning :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8ef6b706995" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Named Parameters in C#]]></title>
            <link>https://medium.com/@saradadeviyerubandi/understanding-named-parameters-in-c-9cca9682bc17?source=rss-5143f057cc5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cca9682bc17</guid>
            <dc:creator><![CDATA[Sarada Devi Yerubandi]]></dc:creator>
            <pubDate>Sat, 14 Sep 2024 16:21:11 GMT</pubDate>
            <atom:updated>2024-09-14T16:21:11.898Z</atom:updated>
            <content:encoded><![CDATA[<p>I am writing this article as I came across a question about Named Parameters in my recent interview for Senior .Net Developer role.</p><p>Before understanding what are Named Parameters, let us see what actually parameters and arguments means.</p><p>In programming, the terms “argument” and “parameter” have slightly different meanings, but are often used interchangeably:</p><blockquote>Parameter is the variable in a function’s definition that represents a value the function expects to receive when called. Parameters define the type and name of the value that will be passed into the function.</blockquote><blockquote>Argument is the actual value that is passed into a function when it is called. Arguments are the concrete values that are assigned to parameters.</blockquote><p>Named parameters/Named Arguments in C# allow you to pass arguments to a method by explicitly specifying the name of the parameter, rather than relying on the order of arguments. This makes your code more readable and reduces the chance of errors when working with methods that have many parameters or optional values.</p><p>It is nothing but to send arguments with the <em>key: value</em> syntax. That way, the order of the arguments does not matter:</p><pre><br>namespace MyApp<br>{<br>    internal class NamedParameters<br>    {<br>        static void Main(string[] args)<br>        {<br><br>            // Using named parameters<br>            NamedParameters oc = new NamedParameters();<br>            oc.PrintInfo(age: 25, lastname: &quot;Yerubandi&quot;, firstname: &quot;Sarada Devi&quot;);<br>        }<br>        private void PrintInfo(string firstname, string lastname, int age )<br>        {<br>            Console.WriteLine($&quot;FirstName: {firstname}, LastName: {lastname}, Age: {age}&quot;);<br>        }<br>    }<br>}</pre><p>In the above C# code snippet, the definition of method <em>PrintInfo </em>is following the order of <em>firstname</em>, <em>lastname </em>and <em>age</em> as parameters respectively. But when we calling that method, we have passed <em>age, lastname</em> and <em>firstname</em> by explicitly mentioning the name of parameter without following the order of parameter list.</p><h4>When to use Named Parameters?</h4><ol><li><strong>Improving Code Readability:</strong> Named parameters clarify what each argument represents, especially when dealing with methods that have multiple parameters or parameters with similar types.</li><li><strong>Working with Optional Parameters:</strong> When a method has optional parameters, you can use named arguments to specify only the parameters you want to change, leaving the others at their default values.</li><li><strong>Avoiding Argument Misordering:</strong> Named parameters help prevent mistakes that occur when you accidentally swap the order of arguments in method calls.</li><li><strong>Long Method Signatures:</strong> For methods with many parameters, named parameters make the method call more understandable without need of checking the method’s definition.</li></ol><p>I hope this guide helped you understand the basic usage of named arguments in C#. Now, I’d love to hear from you! Have you used named arguments in your own C# projects? How have they improved your code, or have you encountered any challenges with them? Feel free to share your thoughts, experiences, or examples in the comments below.</p><p>Thanks for reading. Happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cca9682bc17" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>