<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: boomi1</title>
    <description>The latest articles on DEV Community by boomi1 (@boomi1).</description>
    <link>https://dev.to/boomi1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F909071%2F03da10a6-509f-4307-9026-dc2237eb0292.png</url>
      <title>DEV Community: boomi1</title>
      <link>https://dev.to/boomi1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/boomi1"/>
    <language>en</language>
    <item>
      <title>NET API Controller Without ApiController and ControllerBase?</title>
      <dc:creator>boomi1</dc:creator>
      <pubDate>Sun, 10 Aug 2025 12:56:25 +0000</pubDate>
      <link>https://dev.to/boomi1/net-api-controller-without-apicontroller-and-controllerbase-5bhp</link>
      <guid>https://dev.to/boomi1/net-api-controller-without-apicontroller-and-controllerbase-5bhp</guid>
      <description>&lt;p&gt;Is it possible to write a .NET API controller without using the ApiController attribute and without inheriting from ControllerBase or Controller?&lt;/p&gt;

&lt;p&gt;The short answer is YES.&lt;/p&gt;

&lt;p&gt;But, how will .NET identify this as a controller?&lt;/p&gt;

&lt;p&gt;If a public class’s name ends with the word Controller, it will be considered a controller class, and the methods defined inside that class will be considered action methods. Generally, controllers inherit from ControllerBase or Controller as per convention.&lt;/p&gt;

&lt;p&gt;The major drawback of not explicitly using the ApiController attribute is that functionalities provided by this attribute—such as model binding, model validation, error response handling, etc.—need to be handled manually.&lt;/p&gt;

&lt;p&gt;Conclusion:&lt;br&gt;
The best practice is to always follow the convention by using the ApiController attribute and inheriting from ControllerBase or Controller.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is the difference between string.Empty and ""</title>
      <dc:creator>boomi1</dc:creator>
      <pubDate>Sun, 06 Jul 2025 17:21:00 +0000</pubDate>
      <link>https://dev.to/boomi1/what-is-the-difference-between-stringempty-and--39eo</link>
      <guid>https://dev.to/boomi1/what-is-the-difference-between-stringempty-and--39eo</guid>
      <description>&lt;p&gt;Functionally both represent the string is empty but there are some minor differences between both &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;string.Empty&lt;/strong&gt;&lt;br&gt;
It is read-only field, which can't be used as a compile time constant or in switch statements&lt;/p&gt;

&lt;p&gt;public class HelloWorld&lt;br&gt;
{&lt;br&gt;
    public void Display(string name=string.Empty)&lt;br&gt;
    {&lt;br&gt;
            Console.WriteLine("Display method");&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void Main(string[] args)
{
    HelloWorld h = new HelloWorld();
    h.Display();

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
The above code will give a compile-time error:&lt;/p&gt;

&lt;p&gt;error CS1736: Default parameter value for 'name' must be a compile-time constant&lt;/p&gt;

&lt;p&gt;Similarly, string.Empty can't be used in a switch case. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Whereas "" (an empty string literal)&lt;/strong&gt;&lt;br&gt;
It is considered a compile-time constant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compile-time Constant&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The constant value will be fixed during the compilation rather than at runtime&lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class HelloWorld&lt;br&gt;
{&lt;br&gt;
    public void Display()&lt;br&gt;
    {&lt;br&gt;
        string val = "";&lt;br&gt;
        Console.WriteLine("Empty string:"+val);&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void Main(string[] args)
{
    HelloWorld h = new HelloWorld();
    h.Display();

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Here, the value will fixed at the time of compilation &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt; &lt;br&gt;
Empty string:&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Nested If vs. Ternary Operator in C#: When to Use What</title>
      <dc:creator>boomi1</dc:creator>
      <pubDate>Sun, 22 Jun 2025 12:06:17 +0000</pubDate>
      <link>https://dev.to/boomi1/nested-if-vs-ternary-operator-in-c-when-to-use-what-h7m</link>
      <guid>https://dev.to/boomi1/nested-if-vs-ternary-operator-in-c-when-to-use-what-h7m</guid>
      <description>&lt;p&gt;Choosing between nested if and ternary is bit tricky. Let's see some real-time example to help choose the right one&lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class HelloWorld&lt;br&gt;
{&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
      int age= 18;&lt;br&gt;
      bool hasTicket = true;&lt;br&gt;
      if(age &amp;gt;=18)&lt;br&gt;
      {&lt;br&gt;
          if(hasTicket)&lt;br&gt;
          {&lt;br&gt;
              Console.WriteLine("Allowed to enter");&lt;br&gt;
          }&lt;br&gt;
          else&lt;br&gt;
          {&lt;br&gt;
              Console.WriteLine("Please get the ticket");&lt;br&gt;
          }&lt;br&gt;
      }&lt;br&gt;
      else&lt;br&gt;
      {&lt;br&gt;
          Console.WriteLine("Age must be greater than or equal to 18");&lt;br&gt;
      }&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
Nested if is used in the above example.This can be achieved using ternary operator as well&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Ternary Operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class HelloWorld&lt;br&gt;
{&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
      int age= 18;&lt;br&gt;
      bool hasTicket = true;&lt;br&gt;
      var result = age &amp;lt; 18 ? "Age must be greater than or equal to 18" :&lt;br&gt;
      (hasTicket ? "Allowed to enter" : "Please get the tickets");&lt;br&gt;
      Console.WriteLine(result);&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output for both nested and ternary&lt;/strong&gt;&lt;br&gt;
Allowed to enter &lt;/p&gt;

&lt;p&gt;Use nested if&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the logic is complex
Use ternary operator &lt;/li&gt;
&lt;li&gt;For simple logic&lt;/li&gt;
&lt;li&gt;While assigning or returning a value&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>How Missing Initialization of out Parameters Leads to Errors in C#</title>
      <dc:creator>boomi1</dc:creator>
      <pubDate>Sat, 07 Jun 2025 15:21:36 +0000</pubDate>
      <link>https://dev.to/boomi1/how-missing-initialization-of-out-parameters-leads-to-runtime-errors-in-c-449j</link>
      <guid>https://dev.to/boomi1/how-missing-initialization-of-out-parameters-leads-to-runtime-errors-in-c-449j</guid>
      <description>&lt;p&gt;Missing out variable initialization inside a function leads to  exception &lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class HelloWorld&lt;br&gt;
{&lt;br&gt;
    public void Demo(out int a)&lt;br&gt;
    {&lt;br&gt;
        Console.WriteLine("Demo function");&lt;br&gt;
    }&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
        HelloWorld h = new HelloWorld();&lt;br&gt;
        h.Demo(out int number);&lt;br&gt;
        Console.WriteLine ("Try programiz.pro");&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
The above code will create an exception saying "&lt;strong&gt;error CS0177: The out parameter 'a' must be assigned to before control leaves the current method"&lt;/strong&gt;&lt;br&gt;
using System;&lt;/p&gt;

&lt;p&gt;public class HelloWorld&lt;br&gt;
{&lt;br&gt;
    public void Demo(out int a)&lt;br&gt;
    {&lt;br&gt;
        int data = 10;&lt;br&gt;
        if(data==9)&lt;br&gt;
        {&lt;br&gt;
            a = 6;&lt;br&gt;
            Console.WriteLine("Inside if block");&lt;br&gt;
        }&lt;br&gt;
        Console.WriteLine("Demo function");&lt;br&gt;
    }&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
        HelloWorld h = new HelloWorld();&lt;br&gt;
        h.Demo(out int number);&lt;br&gt;
        Console.WriteLine ("Try programiz.pro");&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;In the above code also the same exception will arise.Even though the initialization is made inside the if block,since the condition fails,it will not go inside the if block and initialization also will not happen.To avoid this, we can follow something I have mentioned in the below code&lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class HelloWorld&lt;br&gt;
{&lt;br&gt;
    public void Demo(out int a)&lt;br&gt;
    {&lt;br&gt;
        int data = 10;&lt;br&gt;
        a = 100;&lt;br&gt;
        if(data==10)&lt;br&gt;
        {&lt;br&gt;
            a = 6;&lt;br&gt;
            Console.WriteLine("Inside if block");&lt;br&gt;
        }&lt;br&gt;
        Console.WriteLine("Demo function");&lt;br&gt;
    }&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
        HelloWorld h = new HelloWorld();&lt;br&gt;
        h.Demo(out int number);&lt;br&gt;
        Console.WriteLine ("Try programiz.pro");&lt;br&gt;
    }&lt;br&gt;
} &lt;br&gt;
In spite of the if block failing, since the initialization happens before the if block the above code will not throw any exception&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt; &lt;br&gt;
Inside if block&lt;br&gt;
Demo function&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; &lt;br&gt;
It's mandatory to initialize the &lt;strong&gt;out&lt;/strong&gt; variable inside the function.&lt;br&gt;
Please do share your feedback!!! ☺️ &lt;/p&gt;

</description>
      <category>csharp</category>
    </item>
    <item>
      <title>What is the difference between ref,out and in keywords in c#</title>
      <dc:creator>boomi1</dc:creator>
      <pubDate>Sun, 25 May 2025 15:45:23 +0000</pubDate>
      <link>https://dev.to/boomi1/what-is-the-difference-between-refout-and-in-keywords-in-c-1n7m</link>
      <guid>https://dev.to/boomi1/what-is-the-difference-between-refout-and-in-keywords-in-c-1n7m</guid>
      <description>&lt;p&gt;In C#, the ref, out, and in keywords are used to pass arguments by reference to methods. This means that instead of passing a copy of the variable, a reference to the original variable is passed. However, these keywords serve different purposes and have distinct behaviors. Let's explore each one in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ref keyword&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Ref keyword is used to pass the value as a reference type inside a function and if it's changed inside a function, the value outside the function will also change since both points to the same address.&lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class Program &lt;br&gt;
{&lt;br&gt;
    public void Demofunc(ref int a)&lt;br&gt;
    {&lt;br&gt;
        a = 10;&lt;br&gt;
        Console.WriteLine("Inside function "+a);&lt;br&gt;
    }&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
       int a = 5;&lt;br&gt;
       Program p = new Program();&lt;br&gt;
       Console.WriteLine("Before calling the function "+a);&lt;br&gt;
       p.Demofunc(ref a);&lt;br&gt;
       Console.WriteLine("After calling the function "+a);&lt;br&gt;
    }&lt;br&gt;
} &lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
Before calling the function 5&lt;br&gt;
Inside function 10&lt;br&gt;
After calling the function 10&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Out keyword&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Out keyword is also very similar to ref keyword the only difference between both is,while passing it as an out keyword &lt;br&gt;
initializing the value is not mandatory but in case of ref keyword it's mandatory.Out keyword is also used to return multiple values from function.&lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class Program &lt;br&gt;
{&lt;br&gt;
    public void Demofunc(out int a)&lt;br&gt;
    {&lt;br&gt;
        a = 10;&lt;br&gt;
        Console.WriteLine("Inside function "+a);&lt;br&gt;
    }&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Program p = new Program();
   p.Demofunc(out int a);
   Console.WriteLine("After calling the function "+a);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
Inside function 10&lt;br&gt;
After calling the function 10&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In keyword&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In keyword is used to pass the value as a reference type but it's not possible to change the value inside the function,modifying the value within the function will cause a error with a message "Cannot assign to variable 'in int' because it is a readonly variable".&lt;/p&gt;

&lt;p&gt;using System;&lt;/p&gt;

&lt;p&gt;public class Program &lt;br&gt;
{&lt;br&gt;
    public void Demofunc(in int a)&lt;br&gt;
    {&lt;br&gt;
        Console.WriteLine("Inside function "+a);&lt;br&gt;
    }&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
       int a= 10;&lt;br&gt;
       Program p = new Program();&lt;br&gt;
       Console.WriteLine(" Before calling the function "+a);&lt;br&gt;
       p.Demofunc(in a);&lt;br&gt;
       Console.WriteLine("After calling the function "+a);&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
Before calling the function 10&lt;br&gt;
Inside function 10&lt;br&gt;
After calling the function 10&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Is It Possible to Have Switch Case Without a Default?</title>
      <dc:creator>boomi1</dc:creator>
      <pubDate>Sun, 18 May 2025 13:15:22 +0000</pubDate>
      <link>https://dev.to/boomi1/is-it-possible-to-have-switch-case-without-a-default-4kjb</link>
      <guid>https://dev.to/boomi1/is-it-possible-to-have-switch-case-without-a-default-4kjb</guid>
      <description>&lt;p&gt;I came across this question while working with switch-case statements and I realised that the answer is both YES AND NO.&lt;/p&gt;

&lt;p&gt;The necessity of a default case depends on where and how you're using the switch. If it's used inside a function that returns a value, then having a default case becomes necessary in certain situations. Otherwise, it's not mandatory.&lt;/p&gt;

&lt;p&gt;Let’s break this down with two scenarios:&lt;/p&gt;

&lt;p&gt;Scenario 1:&lt;/p&gt;

&lt;p&gt;using System;&lt;br&gt;
public class Program&lt;br&gt;
{&lt;br&gt;
    public int Number(int num)&lt;br&gt;
    {&lt;br&gt;
        switch(num)&lt;br&gt;
        {&lt;br&gt;
            case 1: return 1;&lt;br&gt;
            case 2: return 2;&lt;br&gt;
            default: return -1;&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
    public static void Main(string[] args)&lt;br&gt;
    {&lt;br&gt;
        Program p = new Program();&lt;br&gt;
        int result = p.Number(9);&lt;br&gt;
        Console.WriteLine(result);&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
In the above code, we’re returning a value from the function using a switch statement. If none of the case values match, it falls back to the default case and returns -1.&lt;/p&gt;

&lt;p&gt;Now, if we remove the default case, the compiler will throw an error:&lt;/p&gt;

&lt;p&gt;"Not all code paths return a value"&lt;/p&gt;

&lt;p&gt;This is because there's a possibility that no case matches, and the function would have no return path in that situation. Hence, in such scenarios, a default case is necessary to ensure all paths return a value&lt;/p&gt;

&lt;p&gt;Scenario 2:&lt;/p&gt;

&lt;p&gt;public class Program &lt;br&gt;
{&lt;br&gt;
    public void Number(int num)&lt;br&gt;
    {&lt;br&gt;
        switch(num)&lt;br&gt;
        {&lt;br&gt;
             case 1 :&lt;br&gt;
              Console.WriteLine("One");&lt;br&gt;
             case 2 :&lt;br&gt;
               Console.WriteLine("Two");&lt;br&gt;&lt;br&gt;
        }&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void Main(string[] args)
{

   Program p = new Program();
   int result = p.Number(9);
   Console.WriteLine(result);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
In this case, the function has a void return type, meaning it doesn’t return any value. If none of the cases match, the control simply exits the switch block and continues execution. Here, not having a default case is completely valid—though it might not be ideal for readability or handling unexpected input.&lt;/p&gt;

&lt;p&gt;Conclusion:&lt;/p&gt;

&lt;p&gt;Whether or not to include a default case depends on the scenario, especially when it involves return values.&lt;/p&gt;

&lt;p&gt;However, as a best practice, it’s always recommended to include a default case. It improves code readability, helps with debugging, and ensures you handle all unexpected input gracefully.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
