<?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"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[React Developer | Frontend Developer]]></description><link>https://blog.vishalpawar.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Apr 2026 16:44:22 GMT</lastBuildDate><atom:link href="https://blog.vishalpawar.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How I use AI for UI/UX mockup]]></title><description><![CDATA[As a frontend engineers we spend our time creating, modifying and developing responsive layouts daily and This plays very important role in bringing any webapp to the life and the most important part is played by the UI/UX designer who helps us creat...]]></description><link>https://blog.vishalpawar.dev/how-i-use-ai-for-uiux-mockup</link><guid isPermaLink="true">https://blog.vishalpawar.dev/how-i-use-ai-for-uiux-mockup</guid><category><![CDATA[AI]]></category><category><![CDATA[UIUX]]></category><category><![CDATA[UI]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Fri, 16 May 2025 15:59:29 GMT</pubDate><content:encoded><![CDATA[<p>As a frontend engineers we spend our time creating, modifying and developing responsive layouts daily and This plays very important role in bringing any webapp to the life and the most important part is played by the UI/UX designer who helps us creating stunning visually appealing UIs.</p>
<p>But for some personal fun project or some quick mockup we might need a few designs. For finding few UI designs we can use the websites like <a target="_blank" href="https://www.producthunt.com/">Product Hunt</a>, <a target="_blank" href="https://dribbble.com/">Dribbble</a> or many other similar sites.</p>
<p>The above website shows us the stunning designs but integrating the designs we see on these platforms can be overwhelming and for finding the color combinations and color contrasts so the text should be visible and all these things are part of the design. Along with all these things finding design, mixing and matching with our idea will be hard for many developers to design and it is time consuming.</p>
<p>Also, the freshers who gets started with the Frontend they struggle with creating a visually stunning UIs hard as a beginners.</p>
<hr />
<p>My company had an old website they needed it to be completely revamped and we didn’t have any UI/UX designers and they were asking for suggestions on how to we make the colors good and which should be around our company color theme.</p>
<p>But we tried to show many of the designs online but most of them might needed a complete rework as we might need to redesign the all the components of the webpage.</p>
<p>We didn’t want to spend time on completely rewriting the components and re-designing the web pages and The only requirement by manager was it needs little revamp from the perspective of colors.</p>
<hr />
<p>That’s when I started looking around for the option to generate something colors from the company logo and I use this website from <a target="_blank" href="https://color.adobe.com/create/image">Adobe</a> for the extracting the color theme from the logo.</p>
<p>Then I started looking for changing the current UI with some color change as per the logo theme I have been using the <a target="_blank" href="https://uizard.io/">Uizard</a> which is a great tool for taking screenshot and converting it to UI, but after few free trails. It got locked behind a paywall.</p>
<p>Then, I thought of trying the <a target="_blank" href="https://chat.com/">ChatGPT</a> after giving just logo and the screenshot of the old website with proper prompt I started getting UI/UX mockups and After generating multiple mockups. I selected a mockup and asked it to generate the color palette used in this generated UI/UX of my selection and it gave me the list of the color.</p>
<p>After this I just changed the given color code by the AI and the UI was completely changed with proper contrast and added few box shadows to make it modern.</p>
<hr />
<p>Another time, I was working on different UI design had a card which needed some changes in the images that is they wanted to change the illustration images to the icon based images. After making the changes to the given icon the page was not looking visually appealing and was lacking some color.</p>
<p>That when I took the screenshot of the web app and ran through it through ChatGPT and asked it to add some background color to the icons and that when after generating multiple option I added the color given by AI. The generated color were taken from the icons itself and the AI gave a lighter version of color used in icons it made the things more visually appealing.</p>
<p>I shared the latest version of the design with the team and they were happy with the changes.</p>
]]></content:encoded></item><item><title><![CDATA[Host a Static sites with Just Drag and drop]]></title><description><![CDATA[When we start learning Web development. We all build many projects in our local system/computer using the tools like VS Code and other tools but to showcase these projects while in the process of learning to other people online for getting help for t...]]></description><link>https://blog.vishalpawar.dev/host-a-static-sites-with-just-drag-and-drop</link><guid isPermaLink="true">https://blog.vishalpawar.dev/host-a-static-sites-with-just-drag-and-drop</guid><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Web Hosting]]></category><category><![CDATA[server hosting]]></category><category><![CDATA[hosting]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Sun, 21 Aug 2022 17:48:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1661101177731/8lbeLoynC.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we start learning Web development. We all build many projects in our local system/computer using the tools like VS Code and other tools but to showcase these projects while in the process of learning to other people online for getting help for troubleshooting from an online learning community or for sharing the progress of your work with your fellow learner.</p>
<p>To host your static site online follow the below-mentioned steps:</p>
<ul>
<li>Open <a target="_blank" href="https://app.netlify.com/drop">Netlify Drop</a></li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661102444728/bud2pEAlu.png" alt="This is the page of the Netlify Drop" class="image--center mx-auto" /></p>
<ul>
<li>Now drag and drop the folder which contains all the files/assets related to the project on Netlify</li>
</ul>
<p><strong>Note:</strong> If you just want to check how this works and you don't have any project scroll down Netlify has already given some files for checking this feature download the files and upload them.</p>
<ul>
<li>After uploading, you will get the link which you can share with anyone</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661103178884/BDYMtpm2H.png" alt="image.png" /></p>
<p>The link which is generated is by default an HTTPS secure link.</p>
<p><strong>Note:</strong> If you want the permanent link for this project/page you need to sign otherwise the link is valid for only an hour.</p>
]]></content:encoded></item><item><title><![CDATA[Abstract class and method in C#]]></title><description><![CDATA[The abstract classes are a special type of class. Generally, the classes which we declare will have methods with their own implementation as per their requirement that is method definition and method body. but the abstract classes will not have a met...]]></description><link>https://blog.vishalpawar.dev/abstract-class-and-method-in-csharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/abstract-class-and-method-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Learning Journey]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Mon, 04 Jan 2021 12:41:23 GMT</pubDate><content:encoded><![CDATA[<p>The <em>abstract classes</em> are a special type of class. Generally, the classes which we declare will have methods with their own implementation as per their requirement that is method definition and method body. but the <em>abstract classes</em> will not have a method body that is no implementation.</p>
<p>The classes which are declared using the <code>abstract</code> keyword are known as the <em>abstract class</em>. And methods declared using the <code>abstract</code> keyword are known as abstract methods.</p>
<pre><code class="lang-cs"><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Demo</span>
{
  <span class="hljs-keyword">int</span> x = <span class="hljs-number">10</span>;
  <span class="hljs-function"><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">display</span>(<span class="hljs-params"></span>)</span>;
}
</code></pre>
<p>The <code>abstract</code> modifier indicates that the thing being modified has a missing or incomplete implementation.</p>
<p>As you can see in the above code example the class and method are declared using the <code>abstract</code> keyword and the method is just declared without the body(<code>{ }</code>) of the method and the method declaration is ended with <code>;</code>.</p>
<h2 id="use-of-abstract-class-and-methods">Use of abstract class and methods :</h2>
<ul>
<li>The <code>abstract</code> keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title">A</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title">display</span>(<span class="hljs-params"></span>)</span>;
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">B</span> : <span class="hljs-title">A</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">display</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"Implenented in class B"</span>);
        }
    }
</code></pre>
<ul>
<li>The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Shape</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title">GetArea</span>(<span class="hljs-params"></span>)</span>;
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">Square</span> : <span class="hljs-title">Shape</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">GetArea</span>(<span class="hljs-params"></span>)</span>
        {
            <span class="hljs-comment">//implementation</span>
        }
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">Triangle</span> : <span class="hljs-title">Shape</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">GetArea</span>(<span class="hljs-params"></span>)</span>
        {
            <span class="hljs-comment">//implementation</span>
        }
    }
</code></pre>
<p>The <code>Shape</code> <em>abstract class</em> is implemented by the <code>Square</code> and <code>Triangle</code> class which <code>override</code> the <code>GetArea</code> method.</p>
<blockquote>
<p>Note: If a class is inheriting the <em>abstract class</em> but not overriding the <em>abstract method</em> then the class needs to be declared as an <code>abstract</code> class as shown below.</p>
</blockquote>
<pre><code class="lang-cs"><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title">A</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title">GetArea</span>(<span class="hljs-params"></span>)</span>;
    }
    <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title">B</span> : <span class="hljs-title">A</span>
    {
        <span class="hljs-comment">//Method is not implemented</span>
        <span class="hljs-comment">//If this class is not declared abstract then it will throw a compile-time error</span>
    }
</code></pre>
<h2 id="abstract-class-has-the-following-features">Abstract class has the following features :</h2>
<ul>
<li><p>An <em>abstract class</em> cannot be instantiated this means the object of the abstract class can't be created. We can just create a reference variable.</p>
</li>
<li><p>Abstract class can be declared without any abstract methods.</p>
</li>
<li><p>Abstract methods are meant for overridden in another class this means that abstract methods are implicitly virtual method.</p>
</li>
<li><p>Abstract methods can be declared inside only abstract classes.</p>
</li>
<li><p>Abstract class can have <code>static</code> members which can be accessed just using the class name with the <code>.</code> operator.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Basics commands of git]]></title><description><![CDATA[The git is one of the popular VCS that is Version Control System. Which can be used for the managing of the source code.
The git can be used to share code with others and to collaborate with other developers. To learn why use git? check this blog.
gi...]]></description><link>https://blog.vishalpawar.dev/basics-commands-of-git</link><guid isPermaLink="true">https://blog.vishalpawar.dev/basics-commands-of-git</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Sat, 02 Jan 2021 10:14:00 GMT</pubDate><content:encoded><![CDATA[<p>The <code>git</code> is one of the popular <strong><em>VCS</em></strong> that is <strong><em>V</em></strong>ersion <strong><em>C</em></strong>ontrol <strong><em>S</em></strong>ystem. Which can be used for the managing of the source code.</p>
<p>The git can be used to share code with others and to collaborate with other developers. To learn <a target="_blank" href="https://vishalpawarr.hashnode.dev/why-use-git">why use git?</a> check this blog.</p>
<h2 id="git-vs-github"><code>git</code> vs <code>github</code> :</h2>
<p>As you know git is a <strong><em>VCS</em></strong> that was created by the developer of the <em>Linux Kernel</em> in <em>2005</em> by <em>Linus Torvalds</em>. And <strong><em>GitHub</em></strong> is a service built on top of the <em>git</em> and GitHub is owned by <em>Microsoft</em>. Github also has added more features of its own on top of <em>git</em>.</p>
<h2 id="installing-git">Installing git :</h2>
<p>Before we start talking about the <em>git</em> check if you have git installed on your computer by running below command.</p>
<pre><code class="lang-git">git --version
</code></pre>
<p>If <em>git</em> is installed then it will show the version when you run above command.</p>
<p><em>Git</em> is a free and open source you can install it from its official site.</p>
<p><a target="_blank" href="https://git-scm.com/downloads">DOWNLOAD GIT</a></p>
<p><a target="_blank" href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">Git installation instructions for each platform</a></p>
<h2 id="basic-command-to-work-with-file-directory">Basic command to work with file directory :</h2>
<p>These are the basics commands well to know. These commands are helpful to interact with the file directory from <em>git bash</em>.</p>
<ul>
<li><code>mkdir</code> - This command is used to create a folder inside the present directory.</li>
</ul>
<pre><code><span class="hljs-keyword">mkdir</span> FolderName
</code></pre><ul>
<li><code>ls</code> - This is a command used to list all the files inside the directory.<pre><code>ls
</code></pre></li>
<li><code>cd</code> - This command is used to change the directories.<pre><code><span class="hljs-built_in">cd</span>
</code></pre><blockquote>
<p>Note: The <code>cd</code> will move one folder backward from the current directory.</p>
</blockquote>
</li>
</ul>
<pre><code><span class="hljs-built_in">cd</span> FolderName
</code></pre><blockquote>
<p>Note: The <code>cd Foldername</code> will move forward inside the specified FolderName if the folder exists.</p>
</blockquote>
<h2 id="basic-git-commands-for-beginners">Basic <code>git</code> commands for beginners:</h2>
<ul>
<li><code>git config</code> - This command of git is used to configure the <em>git</em> as per the user requirement.</li>
</ul>
<pre><code class="lang-git">git config --global user.name="yourname"
</code></pre>
<pre><code class="lang-git">git config --global user.email="your email"
</code></pre>
<p>By setting the <code>user.name</code> and <code>user.email</code> Whenever you commit to the repo. It will show the name and email in the history log.</p>
<blockquote>
<p>Note: Here <code>--global</code> will set the given value to all the repo, not to the particular repo.</p>
</blockquote>
<ul>
<li><code>git config -l</code> this will list all config settings.</li>
</ul>
<pre><code class="lang-git">git config -l
</code></pre>
<ul>
<li><code>git init</code> - This command of git is used to initialize an empty <em>repository</em> in short it is called <em>repo</em>. The <em>repo</em> in git is like a folder. <em>Repo</em> is the place where the code and configuration files are stored. The repo is also called a <em>working tree</em> this is where the current version of the code is stored.</li>
</ul>
<pre><code class="lang-git">git init
</code></pre>
<ul>
<li><code>git add</code> - This command of git is used to add the files to the <em>staging area</em> from here only the git will track the changes before we commit.</li>
</ul>
<pre><code class="lang-git">git add filename.extension
</code></pre>
<p>In the above command, we can add file by file. example: git add Demo.java. </p>
<p>Adding files to the <em>staging area</em> file by file is not a practical way if we have more files in the repo. We can add all the files to the <code>staging area</code> by using the following command.</p>
<pre><code class="lang-git">git add .
</code></pre>
<p>In this <code>.</code> is a wild card this will add all the files to the *staging area`. This is better compared to writing names of files.</p>
<ul>
<li><code>git status</code> - This command is used to check the <em>status</em>. In git there are <em>traced</em> and <em>untraced</em>files. <em>Traced</em> files are the files that are committed in the <em>git repo</em>. And the <em>untraced files</em> are the files that are new or modified or removed from the working tree.</li>
</ul>
<p>To make the files <em>untraced</em> to <em>traced</em> add the files to the <em>staging area</em> to check this we can use the <code>git status</code> command to do so.</p>
<pre><code class="lang-git">git status
</code></pre>
<ul>
<li><code>git commit</code> - This command is used to save the changes which are in the `staging area<em> to the </em>repo<em>. After we commit the changes </em>repo* creates the history of changes made.</li>
</ul>
<pre><code class="lang-git">git commit
</code></pre>
<p>The above command can be used to commit to the repo. When you execute the above command it will open a default editor which you have set up in <code>git config</code>. The editor will open because it needs a <em>commit message</em> before committing. If you didn't give the commit message then the commit will be aborted.</p>
<p>This is not a perfect way to write a commit message. We can use the other method.</p>
<pre><code class="lang-git">git commit -m "message"
</code></pre>
<p>Unlike the above <code>git commit</code>, This will not open the editor to take the commit message. But, in this one in the same line only we can write the <em>commit message</em>. In this <code>-m</code> git will understand that we are writing the commit message. Example: `git commit -m "Created Demo.java".</p>
<p>After committing the changes to the <em>repo</em> the files will be in the <em>git directory</em> and <em>git</em> will create history.</p>
<p>References if you want to learn more about <em>git</em> :</p>
<ol>
<li><p><a target="_blank" href="https://git-scm.com/book/en/v2">PRO GIT</a> - This book (available online and in print) covers all the fundamentals of how <em>Git</em> works and how to use it. Refer to it if you want to learn more about the git.</p>
</li>
<li><p><a target="_blank" href="https://git-scm.com/docs/gittutorial">GIT TUTORIALS</a> - This tutorial includes a very brief reference of all Git commands available. You can use it to quickly review the commands that you need to use.</p>
</li>
<li><p><a target="_blank" href="https://git-scm.com/doc">GIT OFFICIAL DOCS</a> - This is official documentation of git. Best source to learn about git and it's updates.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Why use git?]]></title><description><![CDATA[The git is a Version Control System, in short, it is known as VCS that is a part of the software industry in day to day life. The git makes life easier by automating hard work that we need to do it by our self manually.
If we didn't have git then we ...]]></description><link>https://blog.vishalpawar.dev/why-use-git</link><guid isPermaLink="true">https://blog.vishalpawar.dev/why-use-git</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Sat, 02 Jan 2021 06:16:33 GMT</pubDate><content:encoded><![CDATA[<p>The <code>git</code> is a <strong><em>V</em></strong>ersion <strong><em>C</em></strong>ontrol <strong><em>S</em></strong>ystem, in short, it is known as <code>VCS</code> that is a part of the software industry in day to day life. The git makes life easier by automating hard work that we need to do it by our self manually.</p>
<p>If we didn't have git then we need to copy the file, again and again, modify the code and rename the file. Like as shown below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1609561673817/QDQwHNlx2.jpeg" alt="hashnode-git-blog.jpg" /></p>
<h3 id="cons-without-vcs">Cons without <code>VCS</code> :</h3>
<ul>
<li><p>The problem with copying the file, again and again, is that we need to make a copy of the file whenever we are modifying the code. and after modifying we need to rename the file.</p>
</li>
<li><p>Generally in Software we work in a team after modification we need to mail the code file to our team whatever changes we made and they will also do the same.</p>
</li>
<li><p>In previous steps we created multiple copies of the file. It is very hard to tell which is the latest copy and which file was created before which one.</p>
</li>
<li><p>When we mail the files to other teammates it is very hard to compare the files for changes they have made. This will may lead to the <code>bugs</code>.</p>
</li>
<li><p>Also, If teammates are sharing their piece of code it is very hard to keep track of who, when, and why the changes were made in the code.</p>
</li>
</ul>
<blockquote>
<p>Note: Before <code>git</code> and <code>VCS</code> there were some tools like 'diff' and <code>wdiff</code> using which we can just compare the files. And there are some graphical tools like <code>meld</code>, <code>KDiff3</code>, and <code>vimdiff</code> which are more advanced than <code>diff</code> etc.</p>
</blockquote>
<h2 id="centralized-version-control">Centralized version control :</h2>
<p>This is another <code>VCS</code> in this one the code is stored in the <code>central server</code> you need to be connected to the server to access the code and its modification and updates.</p>
<h3 id="disadvantages-of-centralized-vc">Disadvantages of centralized VC :</h3>
<ul>
<li><p>In this we need to be always connected to the Server. We cant access the code from anywhere.</p>
</li>
<li><p>If the server was down or got crashed then the team cant work on the project.</p>
</li>
</ul>
<h2 id="git">Git :</h2>
<p>Let's understand how git can help us with a story
Imagine we are cooking some dish with the help of a recipe book. we need to follow step by step procedure to cook a particular recipe. and while cooking you are also watching television. In the beginning, everything was going fine. While watching television you have messed up some of the steps. The dish was ruined because you didn't follow the guide properly.</p>
<p>In the real-life, we can't reverse anything but by using tools like<code>git</code> while writing code if we have made some mistake we can always rollback from problematic changes to the stable version of the code.</p>
<blockquote>
<p>We can use the <code>git</code> as a <code>time machine</code> to move forward or backward.</p>
</blockquote>
<p>Git is useful to know the history of modification in a much-simplified way in an editor. We can also write commit messages before to tell why the change was made.</p>
<h3 id="advantages-of-git">Advantages of <code>git</code> :</h3>
<ul>
<li><p>The code was stored locally on every machine of the team that is every team member had a copy of their own code because of this no connection of server or internet was required to work on a project.</p>
</li>
<li><p>The work will not stop because of some internet or server problems.</p>
</li>
<li><p><code>Git</code> we don't need to make a copy of the file, again and again, to make changes to the file. Because the <code>git</code> will take care of the changes made by who, when, and why.</p>
</li>
<li><p>Using <code>git</code>we can collaborate with other developers like on <code>open source</code> software.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[String in C#]]></title><description><![CDATA[String :

We all know what is String in programming and they are enclosed between the double quotes " " in most of the programming languages. The String may include any characters, numbers, and any special character we can include them in the String....]]></description><link>https://blog.vishalpawar.dev/string-in-csharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/string-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Tue, 29 Dec 2020 10:26:49 GMT</pubDate><content:encoded><![CDATA[<h2 id="string">String :</h2>
<ul>
<li>We all know what is String in programming and they are enclosed between the double quotes <code>" "</code> in most of the programming languages. The String may include any characters, numbers, and any special character we can include them in the String.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System;

<span class="hljs-keyword">class</span> <span class="hljs-title">Demo</span>
{
 <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
 {
    <span class="hljs-keyword">string</span> fav = <span class="hljs-string">"Ironman"</span>;
    String name = <span class="hljs-string">"Tony Stark"</span>;
    String power = <span class="hljs-keyword">new</span> String(<span class="hljs-string">"Intelligence"</span>);

    <span class="hljs-comment">// GetType() is used to find type of variable.</span>
    Console.WriteLine(fav.GetType()); 
    Console.WriteLine(name.GetType());
    Console.WriteLine(power.GetType());
 }
}
<span class="hljs-comment">/*
Output : 
System.String
System.String
System.String
*/</span>
</code></pre>
<blockquote>
<p>Note: The <code>String</code> variable declared using all three gives the same <code>String</code> class object only.</p>
</blockquote>
<h2 id="escape-character-in-string">Escape character in String <code>\</code> :</h2>
<ul>
<li>In programming we use String in many places some times we need to show/use the double quotes inside a message we want to print on console. but we can't do this because of the special property of the double-quotes.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"Hello "</span>RDJ<span class="hljs-string">""</span>); <span class="hljs-comment">//Gives error</span>
        }
    }
</code></pre>
<ul>
<li><p>In the above code the <code>"Hello "</code> and <code>"</code> are considered two separate strings because as we know string that is enclosed between two double quotes and <code>RDJ</code> will not be considered as a string because it is not inside quotes.</p>
</li>
<li><p>Whenever we want to remove the special meaning of any character we can use the escape character <code>\</code>. As shown in the below program.</p>
</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span>
        {
            <span class="hljs-keyword">string</span> name = <span class="hljs-string">"RDJ"</span>;

            Console.WriteLine(<span class="hljs-string">"Hello \"RDJ\""</span>);
        }
    }
<span class="hljs-comment">/*
Output :
Hello "RDJ"
*/</span>
</code></pre>
<blockquote>
<p>Note: If we want to remove the special meaning of any special character we need to add the escape character that is a backslash (<code>\</code>) with the special character as shown in the above code example.</p>
</blockquote>
<h2 id="verbatim-string">Verbatim String <code>@</code> :</h2>
<ul>
<li>The dictionary meaning of the word <code>verbatim</code> is <code>in the same words as were used originally</code>. We call also call the verbatim string a multiline string. If we want to return any lines however it is written then we need to use this verbatim string.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span>
        {
            <span class="hljs-keyword">string</span> sentence = <span class="hljs-string">@"This is a verbatim string this has      spaces          tabs 
            and this also has the next line"</span>;

            Console.WriteLine(sentence);
        }
    }
<span class="hljs-comment">/*
This is a verbatim string this has      spaces          tabs
            and this also has the next line
*/</span>
</code></pre>
<blockquote>
<p>Note: The above verbatim string will print with all the space and tabs and next line. To write <code>verbatim string</code> just add the <code>@</code> symbol in front of the string it will be considered as a verbatim string.</p>
</blockquote>
<h2 id="string-interpolation-dollar">String Interpolation <code>$</code>:</h2>
<ul>
<li><p>String interpolation is nothing but string formating. This is new compared to other old formatting systems in the string.</p>
</li>
<li><p>If we don't use the string formating we need to use the string concatenation which may not properly format the string and we need to format the string with space by typing in the program explicitly. Like in the below program.</p>
</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span>
        {
            <span class="hljs-keyword">string</span> userName = <span class="hljs-string">"Robert"</span>;

            Console.WriteLine(<span class="hljs-string">"Hello"</span>+userName);

            Console.WriteLine(<span class="hljs-string">"Hello "</span>+userName);
        }
    }
<span class="hljs-comment">/*
Output :
HelloRobert
Hello Robert
*/</span>
</code></pre>
<ul>
<li>As you can see we need to concatenate space to string to format the welcome message. The above example is we are concatenating only two strings we can add spaces but when we are concatenating more strings then the code will not be readable and understandable. To make the code look clean we can use the <code>String interpolation</code> just by adding the <code>$</code> sign in front of the string to tell the compiler we are doing string interpolation As shown below.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span>
        {
            <span class="hljs-keyword">string</span> userName = <span class="hljs-string">"Robert"</span>;

            Console.WriteLine(<span class="hljs-string">$"Hello <span class="hljs-subst">{userName}</span>"</span>);
        }
    }
<span class="hljs-comment">/*
Output :
Hello Robert
*/</span>
</code></pre>
<ul>
<li>Compared to the <code>string concatenation</code> the above <code>String interpolation</code> formatted string looks clean to read.</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Inheritance In C#]]></title><description><![CDATA[What is Inheritance?
Inheritance is one of the core concepts of the OOPS.The definition of Inheritance is one class deriving the property of another class is known as inheritance.

The class from which we are going to inherit the properties then that...]]></description><link>https://blog.vishalpawar.dev/inheritance-in-csharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/inheritance-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[learn coding]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Mon, 28 Dec 2020 16:44:20 GMT</pubDate><content:encoded><![CDATA[<h2 id="what-is-inheritance">What is <code>Inheritance</code>?</h2>
<p>Inheritance is one of the core concepts of the <code>OOPS</code>.The definition of Inheritance is one class deriving the property of another class is known as inheritance.</p>
<ul>
<li><p>The class from which we are going to inherit the properties then that class is known as <code>superclass</code> or <code>base class</code> or <code>parent class</code>.</p>
</li>
<li><p>The class which is inheriting the property of the class is known as the <code>subclass</code> or <code>derived class</code> or <code>child class</code>.</p>
</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Subclass</span> : <span class="hljs-title">SuperClass</span>
    {
        <span class="hljs-comment">//methods and fields</span>
    }
</code></pre>
<blockquote>
<p>Note: In <code>C#</code> we use <code>:</code> to inherit other classes.</p>
<h2 id="why-do-we-need-inheritance">Why do we need <code>inheritance</code>?</h2>
</blockquote>
<ul>
<li><p>Using inheritance we can reuse the code instead of rewriting the code again and again.</p>
</li>
<li><p>Using inheritance the number of lines of code can be reduced.</p>
</li>
</ul>
<h2 id="types-of-inheritance">Types of inheritance :</h2>
<p>These are the types of inheritance.</p>
<ol>
<li>Single Inheritance.</li>
<li>Multilevel Inheritance.</li>
<li>Multiple Inheritance.</li>
<li>Hierarchical Inheritance.</li>
<li>Hybrid Inheritance.</li>
</ol>
<h2 id="1-single-inheritance">1. Single Inheritance :</h2>
<ul>
<li>One class inheriting the properties of another class is called as <code>Single inheritance</code>.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">display</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"display() of Superclass"</span>);
        }
    }

    <span class="hljs-keyword">class</span> <span class="hljs-title">B</span> : <span class="hljs-title">A</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">view</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"view() of ChildClass"</span>);
        }
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
        {
            B b = <span class="hljs-keyword">new</span> B();
            <span class="hljs-comment">//Using this the property of the superclass can also be called</span>
            b.view(); <span class="hljs-comment">//Sub class method</span>
            b.display(); <span class="hljs-comment">//Super class method</span>
        }
    }
<span class="hljs-comment">/*
Output :
view() of ChildClass
display() of Superclass
*/</span>
</code></pre>
<h2 id="2-multilevel-inheritance">2. Multilevel Inheritance :</h2>
<p>In this type of inheritance <code>subclass</code> inheritance, the properties of the <code>superclass</code> and this <code>superclass</code> inherit the properties of another <code>superclass</code> is known as the <code>Multilevel Inheritance</code>.</p>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">display</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"display() of class of A"</span>);
        }
    }

    <span class="hljs-keyword">class</span> <span class="hljs-title">B</span> : <span class="hljs-title">A</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">view</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"view() of class of B"</span>);
        }
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">C</span> : <span class="hljs-title">B</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"run() of class of C"</span>);
        }
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
        {
            C c = <span class="hljs-keyword">new</span> C();
            c.run();
            c.view();
            c.display();
        }
    }
*/
Output :
run() <span class="hljs-function">of class of C
<span class="hljs-title">view</span>(<span class="hljs-params"></span>) of class of B
<span class="hljs-title">display</span>(<span class="hljs-params"></span>) of class of A
*/</span>
</code></pre>
<blockquote>
<p>Note: We can access the properties of all the classes using the Object of class <code>C</code> because <code>C</code> is inheriting the class <code>B</code> and class <code>B</code> is inheriting the class <code>A</code>.</p>
</blockquote>
<h2 id="3-multiple-inheritance">3. Multiple Inheritance :</h2>
<p>In this type of inheritance one, <code>subclass</code> inheriting the properties of the multiple classes is known as <code>Multiple Inheritance</code>.</p>
<blockquote>
<p>Note: The <code>multiple inheritance is not supported in C#</code>.</p>
</blockquote>
<h2 id="4-hierarchical-inheritance">4. Hierarchical Inheritance :</h2>
<p>In this type of inheritance from one <code>superclass</code>, multiple <code>subclasses</code> inheritances the properties this creates the hierarchical structure so, this is called as the <code>Hierarchical Inheritance</code>.</p>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">drive</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"drive() of the Car class"</span>);
        }
    }

    <span class="hljs-keyword">class</span> <span class="hljs-title">Tesla</span> : <span class="hljs-title">Car</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">electric</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"electric() of Tesla"</span>);
        }
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">RollsRoyce</span> : <span class="hljs-title">Car</span> 
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">luxury</span>(<span class="hljs-params"></span>)</span>
        {
            Console.WriteLine(<span class="hljs-string">"luxury() of Rolls-Royce"</span>);
        }
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
        {
            Tesla tesla = <span class="hljs-keyword">new</span> Tesla();

            tesla.drive();
            tesla.electric();

            RollsRoyce rolls = <span class="hljs-keyword">new</span> RollsRoyce();

            rolls.drive();
            rolls.luxury();
        }
    }
<span class="hljs-comment">/*
Output :
drive() of the Car class
electric() of Tesla
drive() of the Car class
luxury() of Rolls-Royce
*/</span>
</code></pre>
<blockquote>
<p>Note: In both the <code>subclasses</code> the basic property that is <code>drive()</code> is inherited along with their own methods.</p>
</blockquote>
<h2 id="5-hybrid-inheritance">5. Hybrid Inheritance :</h2>
<p>Hybrid Inheritance is the combination of the other type of inheritance.</p>
]]></content:encoded></item><item><title><![CDATA[Constructor in C#]]></title><description><![CDATA[What is a constructor?

The constructors are the special methods that have the same name as the class name and used to initialize the global variables.

Every class by default have their own constructors even if the programmer doesn't write it explic...]]></description><link>https://blog.vishalpawar.dev/constructor-in-csharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/constructor-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Chrome]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Fri, 25 Dec 2020 10:45:38 GMT</pubDate><content:encoded><![CDATA[<h1 id="what-is-a-constructor">What is a constructor?</h1>
<ul>
<li><p>The <code>constructors</code> are the special methods that have the same name as the class name and used to initialize the global variables.</p>
</li>
<li><p>Every class by default have their own constructors even if the programmer doesn't write it explicitly.</p>
</li>
<li><p>Whenever we create the object what actually happening in the background is we are calling the constructor.</p>
</li>
</ul>
<blockquote>
<p>Note : Changes made using the one object reference will not effect other object reference.</p>
</blockquote>
<pre><code class="lang-cs"><span class="hljs-comment">// Topic: Constructor</span>
<span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass</span> {
  <span class="hljs-comment">// this class has its own Constructor even if the programmer doesn't write explicitly.</span>
}
</code></pre>
<h2 id="types-of-constructor-in-c">Types of Constructor in C#:</h2>
<ol>
<li><p>Default Constructor </p>
</li>
<li><p>Parameterized Constructor</p>
</li>
<li><p>Copy Constructor</p>
</li>
<li><p>Static Constructor</p>
</li>
</ol>
<h2 id="1-default-constructor">1. Default constructor :</h2>
<ul>
<li>This constructor is also known as <code>Zero argument Constructors</code> We can write this constructor as follows :</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-comment">// Topic: Default Constructor</span>
<span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> {
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Test</span>(<span class="hljs-params"></span>)</span>
  {
    Console.WriteLine(<span class="hljs-string">"Default Constructor"</span>);
  }
}
<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass</span> {
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> {
    Test test = <span class="hljs-keyword">new</span> Test();
  }
}
<span class="hljs-comment">/*
Output :
Default Constructor
*/</span>
</code></pre>
<h2 id="2-parameterized-constructor">2. Parameterized Constructor :</h2>
<ul>
<li><p>Parameterized constructor takes the arguments and initialize the value to the given instance of the object. This helps us to make every object different instead of hardcoding the values inside the class.</p>
<pre><code class="lang-cs"><span class="hljs-comment">// Topic: Parameterized Constructor</span>
<span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">class</span> <span class="hljs-title">Account</span> {
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Account</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> name</span>)</span>
{
  Console.WriteLine(<span class="hljs-string">$"This account belongs to <span class="hljs-subst">{name}</span>"</span>);
}
}
<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass</span> {
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> {
  Account a1 = <span class="hljs-keyword">new</span> Account(<span class="hljs-string">"Vishal"</span>);
  Account a2 = <span class="hljs-keyword">new</span> Account(<span class="hljs-string">"Pawar"</span>);
}
}
<span class="hljs-comment">/*
Output :
This account belongs to Vishal
This account belongs to Pawar
*/</span>
</code></pre>
<h2 id="3-copy-constructor">3. Copy Constructor :</h2>
</li>
<li><p>This constructor is used whenever we need a copy of the other object by copying the variable values from another object.</p>
</li>
<li><p>Copy Constructor is a parameterized constructor that takes object reference as an argument and copies the values of the variable and creates a new Object.</p>
<pre><code class="lang-cs"><span class="hljs-comment">// Topic: Copy Constructor</span>
<span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">class</span> <span class="hljs-title">Account</span> {
<span class="hljs-keyword">string</span> name, bankName;
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Account</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> name, <span class="hljs-keyword">string</span> bankName</span>)</span>
  {
  <span class="hljs-keyword">this</span>.name = name;
  <span class="hljs-keyword">this</span>.bankName = bankName;
  }
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Account</span>(<span class="hljs-params">Account ac</span>)</span>
  {
  Console.WriteLine(<span class="hljs-string">"Copying values....."</span>);
 <span class="hljs-keyword">this</span>.name = ac.name;
 <span class="hljs-keyword">this</span>.bankName = ac.bankName;
 Console.WriteLine(<span class="hljs-string">"Copied values....."</span>);
  }
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">display</span>(<span class="hljs-params"></span>)</span>
  {
  Console.WriteLine(<span class="hljs-string">$"The account holder name is <span class="hljs-subst">{name}</span> and bankname is <span class="hljs-subst">{bankName}</span>"</span>);
  }
}
<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass</span> {
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> {
  Account a1 = <span class="hljs-keyword">new</span> Account(<span class="hljs-string">"Vishal"</span>,<span class="hljs-string">"Axis bank"</span>);
  a1.display();
  Account a2 = <span class="hljs-keyword">new</span> Account(a1);
  a2.display();
  }
}
<span class="hljs-comment">/*
Output :
The account holder name is Vishal and bankname is Axis bank
Copying values.....
Copied.....
The account holder name is Vishal and bankname is Axis bank
*/</span>
</code></pre>
</li>
</ul>
<h2 id="4-static-constructor">4. Static Constructor :</h2>
<ul>
<li>The static constructor is used to initialize the <code>static variables</code> of the class and the static constructor executes first whenever the object being created. and, We can't create a static parameterized constructor. Also, the static Constructor executes only once.</li>
</ul>
<blockquote>
<p>Note: We can't overload and pass arguments to the static constructor.</p>
</blockquote>
<pre><code class="lang-cs"><span class="hljs-comment">// Topic: static Constructor</span>
<span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">class</span> <span class="hljs-title">Account</span> {
  <span class="hljs-keyword">static</span> <span class="hljs-keyword">string</span> bankName;
  <span class="hljs-comment">//This class has default Constructor</span>

  <span class="hljs-comment">//static Constructor</span>
  <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-title">Account</span>(<span class="hljs-params"></span>)</span>
  {
    Console.WriteLine(<span class="hljs-string">"Static Constructor called"</span>);
    bankName = <span class="hljs-string">"Axis bank"</span>;
  }
}
<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass</span> {
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> {
    Account a1 = <span class="hljs-keyword">new</span> Account();
    Account a2 = <span class="hljs-keyword">new</span> Account();
  }
}
<span class="hljs-comment">/*
Output :
Static Constructor called
*/</span>
</code></pre>
<blockquote>
<p>Note: In the above code the object created for the <code>Account</code> class was 2 times still the static constructor was executed one time only. By this we can tell the static constructor executes only once for n number of objects created.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Access Modifiers in C#]]></title><description><![CDATA[The access modifiers are used to control the accessibility of the class, variable, method, and constructors throughout the assembly (assembly is in java is known as packages).In other words, access modifiers are used to increase or decrease visibilit...]]></description><link>https://blog.vishalpawar.dev/access-modifiers-in-c-sharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/access-modifiers-in-c-sharp</guid><category><![CDATA[C#]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[learning]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Thu, 24 Dec 2020 08:15:55 GMT</pubDate><content:encoded><![CDATA[<ul>
<li><p>The access modifiers are used to control the accessibility of the <code>class</code>, <code>variable</code>, <code>method</code>, and <code>constructors</code> throughout the assembly (assembly is in java is known as packages).In other words, access modifiers are used to increase or decrease visibility throughout the assembly and classes in projects of C#.</p>
</li>
<li><p>Using the access modifiers we can limit the others from accessing the elements they don't need to access in other classes and packages.</p>
</li>
</ul>
<h2 id="types-of-access-modifiers-in-c">Types of access modifiers in C# :</h2>
<ol>
<li>public</li>
<li>protected</li>
<li>Internal</li>
<li>private</li>
<li>protected internal</li>
<li>private protected</li>
</ol>
<p>Let's understand each one of them below with the program :</p>
<ol>
<li><code>public</code>: The type or member can be accessed by any other code in the <code>same assembly</code> or <code>another assembly</code> that references it.</li>
</ol>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">PointTest</span>
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> x;
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> y;
}

<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass4</span>
{
    <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
    {
        <span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> PointTest();
        <span class="hljs-comment">// Direct access to public members.</span>
        p.x = <span class="hljs-number">10</span>;
        p.y = <span class="hljs-number">15</span>;
        Console.WriteLine(<span class="hljs-string">$"x = <span class="hljs-subst">{p.x}</span>, y = <span class="hljs-subst">{p.y}</span>"</span>);
    }
}
<span class="hljs-comment">// Output: x = 10, y = 15</span>
</code></pre>
<blockquote>
<p>Note: If you change the <code>public</code> access level to <code>private</code> or <code>protected</code>, you will get the error message: <code>'PointTest.y' is inaccessible due to its protection level.</code></p>
</blockquote>
<ol>
<li><code>protected</code>: The type or member can be accessed only by code in the same <code>class</code>, or in a <code>class</code> that is <code>derived</code> from that <code>class</code>.</li>
</ol>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Point</span>
{
    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">int</span> x;
    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">int</span> y;
}

<span class="hljs-keyword">class</span> <span class="hljs-title">DerivedPoint</span>: <span class="hljs-title">Point</span>
{
    <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
    {
        <span class="hljs-keyword">var</span> dpoint = <span class="hljs-keyword">new</span> DerivedPoint();

        <span class="hljs-comment">// Direct access to protected members.</span>
        dpoint.x = <span class="hljs-number">10</span>;
        dpoint.y = <span class="hljs-number">15</span>;
        Console.WriteLine(<span class="hljs-string">$"x = <span class="hljs-subst">{dpoint.x}</span>, y = <span class="hljs-subst">{dpoint.y}</span>"</span>);
    }
}
<span class="hljs-comment">// Output: x = 10, y = 15</span>
</code></pre>
<blockquote>
<p>Note: If you change the access levels of <code>x</code> and <code>y</code> to <code>private</code>, the compiler will issue the error messages:</p>
</blockquote>
<p><code>'Point.y' is inaccessible due to its protection level.</code></p>
<p><code>'Point.x' is inaccessible due to its protection level.</code></p>
<ol>
<li><code>internal</code>: The type or member can be accessed by any code in the <code>same assembly</code>, but <code>not</code> from <code>another assembly</code>.</li>
</ol>
<pre><code class="lang-cs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span>
{  
   <span class="hljs-keyword">internal</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> intM = <span class="hljs-number">0</span>;  
}
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">TestAccess</span>
{  
   <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
   {  
      <span class="hljs-keyword">var</span> myBase = <span class="hljs-keyword">new</span> BaseClass();   
      BaseClass.intM = <span class="hljs-number">444</span>;    
   }  
}
</code></pre>
<blockquote>
<p>Note: Using this <code>internal</code> the visibility of the variable only in the same <code>assembly</code>.</p>
</blockquote>
<ol>
<li><code>private</code>: The type or member can be accessed <code>only</code> by code in the <code>same class</code>.</li>
</ol>
<pre><code class="lang-cs"><span class="hljs-keyword">class</span> <span class="hljs-title">Employee2</span>
{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">string</span> name = <span class="hljs-string">"FirstName, LastName"</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">double</span> salary = <span class="hljs-number">100.0</span>;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> <span class="hljs-title">GetName</span>(<span class="hljs-params"></span>)</span>
    {
        <span class="hljs-keyword">return</span> name;
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">double</span> Salary
    {
        <span class="hljs-keyword">get</span> { <span class="hljs-keyword">return</span> salary; }
    }
}

<span class="hljs-keyword">class</span> <span class="hljs-title">PrivateTest</span>
{
    <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
    {
        <span class="hljs-keyword">var</span> e = <span class="hljs-keyword">new</span> Employee2();

        <span class="hljs-comment">// The data members are inaccessible (private), so</span>
        <span class="hljs-comment">// they can't be accessed like this:</span>
        <span class="hljs-comment">//    string n = e.name;</span>
        <span class="hljs-comment">//    double s = e.salary;</span>

        <span class="hljs-comment">// 'name' is indirectly accessed via method:</span>
        <span class="hljs-keyword">string</span> n = e.GetName();

        <span class="hljs-comment">// 'salary' is indirectly accessed via property</span>
        <span class="hljs-keyword">double</span> s = e.Salary;
    }
}
</code></pre>
<blockquote>
<p>Note: Using <code>private</code> the visibility of the variable <code>name</code> and <code>salary</code> only in the same class. We cant access them in the same assembly also. (Accessing them using the getter and setter methods is another concept known as <code>encapsulation</code>).</p>
</blockquote>
<ol>
<li><code>protected internal</code>:The type or member can be accessed by any code in the assembly in which it's declared, or from within a <code>derived class</code> in <code>another assembly</code>.</li>
</ol>
<pre><code class="lang-cs"><span class="hljs-comment">// Assembly1.cs</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span>
{
   <span class="hljs-keyword">protected</span> <span class="hljs-keyword">internal</span> <span class="hljs-keyword">int</span> myValue = <span class="hljs-number">0</span>;
}

<span class="hljs-keyword">class</span> <span class="hljs-title">TestAccess</span>
{
    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Access</span>(<span class="hljs-params"></span>)</span>
    {
        <span class="hljs-keyword">var</span> baseObject = <span class="hljs-keyword">new</span> BaseClass();
        baseObject.myValue = <span class="hljs-number">5</span>;
    }
}

<span class="hljs-comment">// Assembly2.cs</span>
<span class="hljs-keyword">class</span> <span class="hljs-title">DerivedClass</span> : <span class="hljs-title">BaseClass</span>
{
    <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
    {
        <span class="hljs-keyword">var</span> baseObject = <span class="hljs-keyword">new</span> BaseClass();
        <span class="hljs-keyword">var</span> derivedObject = <span class="hljs-keyword">new</span> DerivedClass();

        <span class="hljs-comment">// Error CS1540, because myValue can only be accessed by</span>
        <span class="hljs-comment">// classes derived from BaseClass.</span>
        <span class="hljs-comment">// baseObject.myValue = 10;</span>

        <span class="hljs-comment">// OK, because this class derives from BaseClass.</span>
        derivedObject.myValue = <span class="hljs-number">10</span>;
    }
}
</code></pre>
<blockquote>
<p>Note: This access modifier is a combination of both <code>protected internal</code> here the properties of both access specifiers are combined that is., it is accessible in the same <code>assembly</code> and another assembly's derived class.</p>
</blockquote>
<ol>
<li><code>private protected</code>: The type or member can be accessed <code>only within its declaring assembly</code>, by code in the same <code>class</code>, or in a type that is <code>derived</code> from that <code>class</code>.</li>
</ol>
<pre><code class="lang-cs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span>
{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">protected</span> <span class="hljs-keyword">int</span> myValue = <span class="hljs-number">0</span>;
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">DerivedClass1</span> : <span class="hljs-title">BaseClass</span>
{
    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Access</span>(<span class="hljs-params"></span>)</span>
    {
        <span class="hljs-keyword">var</span> baseObject = <span class="hljs-keyword">new</span> BaseClass();

        <span class="hljs-comment">// Error CS1540, because myValue can only be accessed by</span>
        <span class="hljs-comment">// classes derived from BaseClass.</span>
        <span class="hljs-comment">// baseObject.myValue = 5;</span>

        <span class="hljs-comment">// OK, accessed through the current derived class instance</span>
        myValue = <span class="hljs-number">5</span>;
    }
}
</code></pre>
<p>Note: Like the <code>protected internal</code> this is also a combination of two access modifiers and 'private protected<code>combines the properties of both access modifiers that is.,</code>private<code>and</code>protected<code>.  Unlike</code>private<code>using this, we can access the properties in</code>same <code>assembly</code>.</p>
]]></content:encoded></item><item><title><![CDATA[Introduction to class and object in C#]]></title><description><![CDATA[Whenever we are dealing with the OOPS concepts we are generally using the class and object.
What is class?
The class and objects are the blueprint or prototype. The class can be created for the entity which has states and behaviors. The entity may be...]]></description><link>https://blog.vishalpawar.dev/introduction-to-class-and-object-in-csharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/introduction-to-class-and-object-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Blogging]]></category><category><![CDATA[Best of Hashnode]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Wed, 23 Dec 2020 16:30:16 GMT</pubDate><content:encoded><![CDATA[<p>Whenever we are dealing with the <code>OOPS</code> concepts we are generally using the <code>class and object</code>.</p>
<h2 id="what-is-class">What is <code>class</code>?</h2>
<p>The <code>class and objects</code> are the <code>blueprint</code> or <code>prototype</code>. The class can be created for the entity which has <code>states and behaviors</code>. The entity may be a living or non-living thing.</p>
<h2 id="declaring-the-class">Declaring the <code>class</code> :</h2>
<pre><code class="lang-cs">AccessModifiers <span class="hljs-keyword">class</span> <span class="hljs-title">ClassName</span>
{
    <span class="hljs-comment">// fields also known as variables</span>

    <span class="hljs-comment">// functions also known as methods</span>
}
</code></pre>
<ul>
<li>The class will always have <code>access modifiers</code> to control the visibility of the class. To learn more about the access modifiers please check my <a target="_blank" href="https://vishalpawarr.hashnode.dev/access-modifiers-in-c-sharp">blog on access modifiers</a>.</li>
</ul>
<blockquote>
<p>Note: If we are not writing the <code>access modifiers</code> explicitly then the class will by default <code>internal</code> as access modifier.</p>
</blockquote>
<ul>
<li><p>The classes are declared using the <code>class</code> keyword.</p>
</li>
<li><p>The class will have the name and body the body of the class is surrounded using the <code>{ }</code>.</p>
</li>
</ul>
<h2 id="example">Example :</h2>
<pre><code class="lang-cs"><span class="hljs-keyword">namespace</span> <span class="hljs-title">Demo</span>
{
    <span class="hljs-keyword">class</span> <span class="hljs-title">Add</span>
    {
        <span class="hljs-keyword">int</span> a = <span class="hljs-number">10</span>;
        <span class="hljs-keyword">int</span> b = <span class="hljs-number">20</span>;
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> sum;

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Sum</span>(<span class="hljs-params"></span>)</span>
        {
            sum = a + b;
        }
    }
    <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
        {
            Add <span class="hljs-keyword">add</span> = <span class="hljs-keyword">new</span> Add();

            <span class="hljs-keyword">add</span>.Sum();
            Console.WriteLine(<span class="hljs-string">$"The sum of a and b : <span class="hljs-subst">{<span class="hljs-keyword">add</span>.sum}</span>"</span>);
        }

    }
}
<span class="hljs-comment">/*
Output :
The sum of a and b: 30
*/</span>
</code></pre>
<p>Explanation :</p>
<ul>
<li><p><code>namespace</code> is a way of organizing the code and <code>namespace</code> also helps in avoiding the naming collision of the class.</p>
</li>
<li><p>The <code>access modifiers</code> for the above class is <code>internal</code> because we didn't mention it explicitly.</p>
</li>
<li><p>The class <code>Add</code> has variables like <code>a</code>, <code>b</code>, and <code>sum</code>. The <code>Add</code> class also has a method named <code>Sum</code> which takes above both values from <code>a</code> and <code>b</code> using the operator <code>+</code> performs the addition operation and store the value returned value inside the <code>sum</code> variable.</p>
</li>
</ul>
<blockquote>
<p>Note: In <code>C#</code> the execution of the program from <code>Main()</code> only.</p>
</blockquote>
<ul>
<li><p>To access the variables and methods of the different classes we need to create the object of that class.</p>
</li>
<li><p>To create the object of the <code>class</code> we use the <code>new</code> keyword.</p>
</li>
</ul>
<blockquote>
<p>Note: The objects created using the <code>new</code> keyword are stored inside the <code>heap area</code>.</p>
</blockquote>
<ul>
<li>Whenever we create the object of the class the constructor of that class gets called.</li>
</ul>
<blockquote>
<p>Note: Each and every <code>class</code> has will have a constructor of its own even if we didn't write the constructor explicitly. To learn more about Constructor please check my <a target="_blank" href="https://vishalpawarr.hashnode.dev/constructor-in-csharp">blog on constructor</a>.</p>
</blockquote>
<ul>
<li>By using the object reference we can call the methods and variable and perform the required operation.</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Object Class in C#]]></title><description><![CDATA[Every class in C# inherits the property of the Object class implicitly that is., the Object class is the superclass or super most class of each and every class.

using System;
class Base:Object {
  public static void Main() 
  {
    //using this clas...]]></description><link>https://blog.vishalpawar.dev/object-class-in-csharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/object-class-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[visual studio]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Tue, 22 Dec 2020 16:06:59 GMT</pubDate><content:encoded><![CDATA[<ul>
<li>Every <code>class</code> in C# <code>inherits</code> the property of the <code>Object</code> class implicitly that is., the <code>Object</code> class is the <code>superclass</code> or super most class of each and every class.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">class</span> <span class="hljs-title">Base</span>:<span class="hljs-title">Object</span> {
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> 
  {
    <span class="hljs-comment">//using this class we can access all the properties of Base class and Object class.</span>
  }
}
</code></pre>
<blockquote>
<p>Note: Even if we didn't inherit the <code>Object</code> class <code>explicitly</code> then also the <code>compiler</code> will <code>implicitly</code> inherit the <code>Object</code> class to all the class.</p>
</blockquote>
<ul>
<li>If some class is inheriting properties of other class then that class will not implicitly inherit the Object class because C# doesn't support the multiple inheritances.</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System;

<span class="hljs-keyword">class</span> <span class="hljs-title">Super</span> {
  <span class="hljs-comment">//This class will inherit the Object class implicitly.</span>
}

<span class="hljs-keyword">class</span> <span class="hljs-title">Base</span>:<span class="hljs-title">Super</span>, <span class="hljs-title">Object</span> {
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> 
  {
    <span class="hljs-comment">//This class inherited the Superclass and we can't inherit implicitly or explicitly the Object class.</span>
  }
}
</code></pre>
<ul>
<li>We have some useful methods in the <code>Object</code> class which we can use in our program.</li>
</ul>
<h2 id="methods-of-object-class">Methods of <code>Object</code> class :</h2>
<p><code>Equals(Object)</code>: Determines whether the specified object is equal to the current object.</p>
<p><code>Equals(Object, Object)</code>: Determines whether the specified object instances are considered equal.</p>
<p><code>Finalize()</code>: Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.</p>
<p><code>GetHashCode()</code>: Serves as the default hash function.</p>
<p><code>GetType()</code>: Gets the Type of the current instance.</p>
<p><code>MemberwiseClone()</code>: Creates a shallow copy of the current Object.</p>
<p><code>ReferenceEquals(Object, Object)</code>: Determines whether the specified Object instances are the same instance.</p>
<p><code>ToString()</code>: Returns a string that represents the current object.</p>
<h2 id="overriding-methods-of-object-class">Overriding methods of Object class :</h2>
<ul>
<li><p>The <code>Object</code> class has multiple methods but we can only <code>override</code> three methods from the <code>Object</code> class.</p>
</li>
<li><p><code>GetHashCode()</code>, <code>Equals(Object)</code>, and <code>ToString()</code> only these methods of the <code>Object</code> class can be <code>overridden</code> by the programmer.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[The foreach loop in C#]]></title><description><![CDATA[Loops in C#:

Introduction :

There are multiple ways to writing the loops in C# the most basics loops in any programming languages are for and while loop. In C# we have another type of advance loop that is the foreach loop. We will see the syntax an...]]></description><link>https://blog.vishalpawar.dev/the-foreach-loop-in-c-sharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/the-foreach-loop-in-c-sharp</guid><category><![CDATA[C#]]></category><category><![CDATA[basics]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Learning Journey]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Tue, 22 Dec 2020 06:10:27 GMT</pubDate><content:encoded><![CDATA[<h1 id="loops-in-c">Loops in C#:</h1>
<hr />
<h2 id="introduction">Introduction :</h2>
<ul>
<li><p>There are multiple ways to writing the loops in <code>C#</code> the most basics loops in any programming languages are <code>for</code> and <code>while</code> loop. In <code>C#</code> we have another type of advance loop that is the <code>foreach</code> loop. We will see the <code>syntax</code> and execution of the <code>foreach</code> loop below.</p>
</li>
<li><p>Before we talk about the advanced <code>foreach</code> loop let me just give a brief explanation of the other looping condition.</p>
</li>
</ul>
<h3 id="types-of-loops">Types of Loops :</h3>
<table>
<thead>
<tr>
<td>Loops</td><td>When to use the Loop</td></tr>
</thead>
<tbody>
<tr>
<td><code>for</code></td><td>We can use this loop whenever we know the starting and ending conditions.</td></tr>
<tr>
<td><code>while</code></td><td>We can use this loop whenever we don't know the starting condition but we know the end condition.</td></tr>
<tr>
<td><code>do-while</code></td><td>We can use this loop whenever we want to execute the loop at least one time before it checks the condition.</td></tr>
<tr>
<td><code>foreach</code></td><td>We can use this advanced for loop in concepts like Array and other data structure concepts where we don't want to use the index number to access the elements or Some of the data structure they don't have the index concept.</td></tr>
</tbody>
</table>
<h2 id="foreach-loop"><code>foreach</code> loop :</h2>
<ul>
<li><code>foreach</code> is advanced <code>for</code> loop which can be used to access the element of the collection without using indexes.</li>
</ul>
<h3 id="syntax">Syntax :</h3>
<pre><code class="lang-cs"><span class="hljs-keyword">foreach</span>(data_type var_name <span class="hljs-keyword">in</span> collection_var) {
    <span class="hljs-comment">//statements</span>
}
</code></pre>
<h3 id="understanding-the-foreach-loop">Understanding the <code>foreach</code> loop :</h3>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System;
<span class="hljs-comment">// Topic: foreach</span>
<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass</span> {
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span> (<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span> 
  {
    <span class="hljs-keyword">int</span>[] num = {<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>};
    Console.WriteLine(<span class="hljs-string">"Using the for loop"</span>);
    <span class="hljs-comment">//for loop</span>
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i&lt;num.Length;i++)
    {
      Console.WriteLine(num[i]);
    }

    Console.WriteLine(<span class="hljs-string">"Using the foreach loop"</span>);
    <span class="hljs-comment">//foreach loop</span>
    <span class="hljs-keyword">foreach</span>(<span class="hljs-keyword">int</span> a <span class="hljs-keyword">in</span> num)
    {
      Console.WriteLine(a);
    }
  }
}
</code></pre>
<p>Output :</p>
<pre><code class="lang-cs">Using the <span class="hljs-keyword">for</span> loop
<span class="hljs-number">1</span>
<span class="hljs-number">2</span>
<span class="hljs-number">3</span>
<span class="hljs-number">4</span>
<span class="hljs-number">5</span>
Using the <span class="hljs-keyword">foreach</span> loop
<span class="hljs-number">1</span>
<span class="hljs-number">2</span>
<span class="hljs-number">3</span>
<span class="hljs-number">4</span>
<span class="hljs-number">5</span>
</code></pre>
<h2 id="explanation">Explanation :</h2>
<h3 id="for-loop"><code>for</code> loop :</h3>
<ul>
<li>In the above code, you can see using the <code>for</code> loop we need to access the elements using the index value. Here using the <code>for</code> loop we need to keep the index values in check that is if the index values are in the range of the given collection/array length or else this will lead to the <code>System.IndexOutOfRangeException</code>. And also, we need to increment/decrement the index value as per our required outputs.</li>
</ul>
<h3 id="foreach-loop"><code>foreach</code> loop :</h3>
<ul>
<li>Like <code>for</code> loop this doesn't use any kind of index to retrieve elements from the array. This advanced <code>foreach</code> loop will take the array and retrieve the elements one by one until the array will not have any elements left. This happens because if the array has elements then the <code>foreach</code> loop returns <code>true</code> else it will return <code>false</code> and stop the execution.</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Arrays in C#]]></title><description><![CDATA[The array is a data structure that is used to store the homogeneous data inside. We can store any data that is a primitive type or any Object type inside an array but the data should be of the same type and it should be in the specified array size.
H...]]></description><link>https://blog.vishalpawar.dev/arrays-in-csharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/arrays-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Microsoft]]></category><category><![CDATA[visual studio]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Mon, 21 Dec 2020 15:43:47 GMT</pubDate><content:encoded><![CDATA[<p>The array is a data structure that is used to store the homogeneous data inside. We can store any data that is a primitive type or any Object type inside an array but the data should be of the same type and it should be in the specified array size.</p>
<h2 id="how-to-create-an-array">How to create an array :</h2>
<pre><code class="lang-cs">type[] variable-name = <span class="hljs-keyword">new</span> type[size];
<span class="hljs-comment">// example</span>
<span class="hljs-keyword">int</span>[] num = <span class="hljs-keyword">new</span> num[<span class="hljs-number">5</span>];
</code></pre>
<ul>
<li>This is the basic syntax of array creation.<ul>
<li><code>type</code> - Type is nothing but datatype or object type of the array you want to create.</li>
<li><code>variable-name</code> - This is a variable name that can be used to access the elements of an array.</li>
<li><code>new</code> - This is a keyword of <code>C#</code> which is used for object creation.</li>
<li><code>size</code> - The size is used to create a specific length array element.</li>
</ul>
</li>
</ul>
<blockquote>
<p>Note: Array is an object and every array has a fixed size and the size of the array can't be changed after creation.</p>
</blockquote>
<h2 id="creating-an-array-using-different-techniques">Creating an array using  different techniques :</h2>
<p>The array can be created in multiple ways they are :</p>
<h2 id="way-1">Way 1:</h2>
<p>The array can be created in 3 steps array <code>declaration</code>, <code>creation</code>, and <code>initialization</code>.</p>
<h3 id="i-array-declaration">i. Array declaration :</h3>
<pre><code class="lang-cs">type variable_name[];
<span class="hljs-comment">//example</span>
<span class="hljs-keyword">int</span> num[];
</code></pre>
<ul>
<li>The above line of code will just declare the <code>int</code> array with the name num.</li>
</ul>
<h3 id="ii-array-creation">ii. Array creation :</h3>
<pre><code class="lang-cs">variable_name = <span class="hljs-keyword">new</span> type[size];
<span class="hljs-comment">//example</span>
num = <span class="hljs-keyword">new</span> <span class="hljs-keyword">int</span>[<span class="hljs-number">3</span>];
</code></pre>
<ul>
<li>The above line of code will create the array with a given size that is <code>3</code>. This array <code>num</code> will have the size of 3. and all the elements of the array are default values with respect to the datatypes here in this case datatype is <code>int</code> so the default value is <code>0</code>.</li>
</ul>
<h3 id="iii-array-initialization">iii. Array initialization :</h3>
<pre><code class="lang-cs">variable_name[index];
<span class="hljs-comment">//example</span>
num[<span class="hljs-number">0</span>] = <span class="hljs-number">11</span>;
num[<span class="hljs-number">1</span>] = <span class="hljs-number">22</span>;
num[<span class="hljs-number">2</span>] = <span class="hljs-number">33</span>;
</code></pre>
<blockquote>
<p>Note: The array index starts from <code>zero</code></p>
</blockquote>
<ul>
<li><p>As we have initialized the array with size 3. We can initialize the array element using an index.</p>
</li>
<li><p>For the above example with size <code>3</code> index values will be <code>0</code>, <code>1</code>, '2' and the values assigned are '11`, '22', '33' respectively.</p>
</li>
</ul>
<h2 id="way-2">Way 2 :</h2>
<p>As we have seen above it requires 3 steps to create an array but we can do it in a different way as shown below.</p>
<pre><code class="lang-cs">type[] variable_name = {e1,e2,..en};
<span class="hljs-comment">//or</span>
type[] variable_name = <span class="hljs-keyword">new</span> type[]{e1,e2,..en};
<span class="hljs-comment">//both of the above line does the same thing</span>
</code></pre>
<ul>
<li>In the above syntax as you see we can declare and initialize the values of the array without mentioning the <code>size</code>. We can use this method whenever we know the values we are going to store.</li>
</ul>
<blockquote>
<p>Note: We can use any technique to create the array depending on the requirements.</p>
</blockquote>
<h2 id="accessing-the-array-elements">Accessing the array elements :</h2>
<ul>
<li><p>We can retrieve/access the array elements using the loops. We use the <code>for</code>, <code>while</code>, and <code>foreach</code> loop to access the array elements.</p>
</li>
<li><p>We are going to learn about retrieving the array element using the <code>for</code> loop.</p>
</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">class</span> <span class="hljs-title">MainClass</span> {
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> 
  {
    <span class="hljs-comment">//Array declaration and initialization</span>
    <span class="hljs-keyword">int</span>[] num = {<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>}; 

    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i&lt;num.Length;i++)
    {
      Console.Write(num[i]+<span class="hljs-string">" "</span>);
    }
  }
}
</code></pre>
<blockquote>
<p>Note: We can use the <code>Length</code> property of the array to find the unknown array length.</p>
</blockquote>
<ul>
<li>The above <code>for</code> loop will create the index values using the given condition. The index values generated by the <code>for</code> loop for the above-given condition of the index are <code>0</code>, <code>1</code>, and <code>2</code>.</li>
<li>The above code inside the loop is the same as adding the array element to the respective index as we have seen above. Instead of adding we can retrieve the element using an index same as adding them to the respective index.</li>
</ul>
<h2 id="changing-the-array-element-using-the-index">Changing the array element using the index :</h2>
<p>We can update the array elements by retrieving them using the index and reassigning them with the new values.</p>
<pre><code class="lang-cs">num[<span class="hljs-number">0</span>] = <span class="hljs-number">44</span>;
</code></pre>
<blockquote>
<p>Note: If you try to store the <code>string</code> values inside the <code>int</code> array it will throw an exception that is <code>Cannot implicitly convert type 'string' to 'int'</code>.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Var and Dynamic Keywords in C#]]></title><description><![CDATA[The var and dynamic types in C#:

Primitive Datatypes :

Generally we use the datatype to declare and store the value inside the variable but in the C#, we have another 2 ways to do the same that is using the var and dynamic keywords we will discuss ...]]></description><link>https://blog.vishalpawar.dev/var-and-dynamic-keywords-in-c-sharp</link><guid isPermaLink="true">https://blog.vishalpawar.dev/var-and-dynamic-keywords-in-c-sharp</guid><category><![CDATA[C#]]></category><category><![CDATA[beginner]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Vishal Pawar]]></dc:creator><pubDate>Fri, 18 Dec 2020 08:28:57 GMT</pubDate><content:encoded><![CDATA[<h1 id="the-var-and-dynamic-types-in-c">The <code>var</code> and <code>dynamic</code> types in C#:</h1>
<hr />
<h2 id="primitive-datatypes">Primitive Datatypes :</h2>
<ul>
<li>Generally we use the datatype to declare and store the value inside the variable but in the C#, we have another 2 ways to do the same that is using the <code>var</code> and <code>dynamic</code> keywords we will discuss these keywords in later parts of this blog.
###<pre><code class="lang-cs">datatype variableName = <span class="hljs-keyword">value</span>; <span class="hljs-comment">//this is declaration of variable using the primitive data types</span>
<span class="hljs-keyword">int</span> a = <span class="hljs-number">10</span>;
</code></pre>
<h2 id="var-type"><code>var</code> type :</h2>
</li>
<li><p>The <code>var</code> type is introduced in the <strong>C# 3.0</strong> version. The <code>var</code> are those variables that are declared without specifying the type explicitly. Instead, we use the <code>var</code> keyword to declare the variables. The type check occurs during the compilation. These are not designed to replace the normal variable declaration, it is designed to handle the special case situation.</p>
<ul>
<li>Difference between the implicitly typed and explicitly typed<pre><code class="lang-cs"><span class="hljs-keyword">int</span> i = <span class="hljs-number">10</span>; <span class="hljs-comment">// Explicitly type of the variable is mentioned.</span>
<span class="hljs-keyword">var</span> i = <span class="hljs-number">10</span>; <span class="hljs-comment">// Implicitly type check occurs by the compiler</span>
</code></pre>
<h2 id="dynamic-type"><code>dynamic</code> type :</h2>
</li>
</ul>
</li>
<li>The <code>dynamic</code> type is introduced in the <strong>C# 4.0</strong> version.
Here also we don't need to mention the type of variable like the <code>var</code>. Here we can declare the variable using the <code>dynamic</code> keyword. The compiler will not check the type of the variable which is declared using the <code>dynamic</code> keyword during compile time. This is used to avoid the compile-time type checking.<ul>
<li>Difference between the implicitly typed and explicitly typed<pre><code class="lang-cs"><span class="hljs-keyword">int</span> num = <span class="hljs-number">8</span>; <span class="hljs-comment">// Explicitly type of variable is mentioned.</span>
<span class="hljs-keyword">dynamic</span> = <span class="hljs-number">8</span>; <span class="hljs-comment">//Implicitly type check occurs during runtime</span>
</code></pre>
</li>
</ul>
</li>
</ul>
]]></content:encoded></item></channel></rss>