<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mazdak Parnian</title>
    <description>The latest articles on DEV Community by Mazdak Parnian (@purejoymind).</description>
    <link>https://dev.to/purejoymind</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1158490%2Feca4c0b4-b733-45bd-8a4c-2e6251977759.jpg</url>
      <title>DEV Community: Mazdak Parnian</title>
      <link>https://dev.to/purejoymind</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/purejoymind"/>
    <language>en</language>
    <item>
      <title>Streams in C#</title>
      <dc:creator>Mazdak Parnian</dc:creator>
      <pubDate>Thu, 06 Nov 2025 14:24:00 +0000</pubDate>
      <link>https://dev.to/purejoymind/streams-in-c-2ahh</link>
      <guid>https://dev.to/purejoymind/streams-in-c-2ahh</guid>
      <description>&lt;p&gt;Before your programs know and understand the content of the information that's being passed over the network, they need a reliable way to transfer and receive information.&lt;/p&gt;

&lt;p&gt;Streams offer just that. But before diving too deep in the network side, we need to take a look at streams in general! They are one of the fundamental structures of interacting with data outside of your program (not just through networks)!&lt;/p&gt;

&lt;p&gt;When I started out as a developer, they used to confuse me a lot, but hopefully in this post I can help you leave the confusion behind!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Base &lt;code&gt;Stream&lt;/code&gt; Class
&lt;/h2&gt;

&lt;p&gt;When talking about streams, we're strictly talking about transferring data; and when your only concern is just moving data, that means that the data is raw bytes. The base &lt;code&gt;Stream&lt;/code&gt; class in C# represents that idea wholeheartedly. &lt;br&gt;
The base class only provides direct access to an ordered sequence of bytes, but it doesn't give a meaningful way of understanding the data. &lt;/p&gt;

&lt;p&gt;You can think of it as like the Highway over which the data passes through. It's the road, you don't care about what types of cars go through it.&lt;/p&gt;

&lt;p&gt;A stream is an active connection to the data source. Like any data source it needs to be opened and closed and then disposed before you're done with it. This should probably make sense to you if you've already worked with external connections such as database connections and such. &lt;/p&gt;

&lt;p&gt;External connections mean that our program must interact with the underlying &lt;strong&gt;&lt;em&gt;Operating System&lt;/em&gt;&lt;/strong&gt; in order to get what it needs, that also makes our program responsible for the resources the OS is giving it, thus why we need to &lt;strong&gt;&lt;em&gt;open&lt;/em&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;close&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;dispose&lt;/em&gt;&lt;/strong&gt; of such connections.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Stream&lt;/code&gt; class gives us three important actions: &lt;strong&gt;&lt;em&gt;Read&lt;/em&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;Write&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;Seek&lt;/em&gt;&lt;/strong&gt; an index of a sequence of bytes.&lt;/p&gt;
&lt;h3&gt;
  
  
  Writing to Streams
&lt;/h3&gt;

&lt;p&gt;The streams do not bother themselves with how complicated objects are represented. It's simply not their job, they are the road over which raw data travels. so if we want to send data over streams, we first have to convert/serialize our data to bytes (&lt;code&gt;byte[]&lt;/code&gt;, or &lt;code&gt;byte&lt;/code&gt; depending on the size of the data).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"stream data into a file"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UTF8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="c1"&gt;// Notice the ioStream's type =&amp;gt; Stream&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;ioStream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FileStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@"strm.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   
    &lt;span class="n"&gt;FileMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OpenOrCreate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CanWrite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
    &lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

&lt;span class="k"&gt;else&lt;/span&gt;  
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Couldn't write to our data stream."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the ioStream variables type, it's a &lt;code&gt;Stream&lt;/code&gt; not a &lt;code&gt;FileStream&lt;/code&gt;. That's because it really doesn't matter where the data is coming from. If we change the &lt;code&gt;FileStream&lt;/code&gt; to a &lt;code&gt;NetworkStream&lt;/code&gt;, how we work with that stream would mostly be the same. &lt;br&gt;
The &lt;code&gt;Stream&lt;/code&gt; class provides us with enough data, that includes letting us knowing if the stream is ready to work with with the &lt;code&gt;CanWrite&lt;/code&gt; property. This also, in a small way, helps error handling by avoiding &lt;code&gt;try/catch&lt;/code&gt; blocks.&lt;/p&gt;

&lt;p&gt;Since streams work exclusively with raw data, they don't bother themselves with anything else. We must provide them with raw data, so no matter what the data is, we must serialize it into a sequence of bytes. &lt;/p&gt;

&lt;p&gt;We can convert strings to bytes using &lt;code&gt;Encoding.UTF8.GetBytes&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;In the same way the a stream has no idea of the actual contents of the sequence of data its transferring, it also doesn't know where to start reading and when to stop. it needs the array of bytes, then instructions on where to start reading from, and precisely how many of those bytes it should write. &lt;/p&gt;

&lt;p&gt;The second parameter in the &lt;code&gt;Write&lt;/code&gt; method signature is your starting index. It starts at 0, just like the array does. The third parameter is the total number of bytes you want to send in this &lt;code&gt;Write&lt;/code&gt; operation. &lt;br&gt;
There is a runtime error checking on this and if you try to send more bytes than there are left in the array (starting from whatever index you designate), you'll get an index out-of-bounds error.&lt;/p&gt;

&lt;p&gt;You're giving the stream the data, and where to read from that data.&lt;/p&gt;
&lt;h4&gt;
  
  
  Seek
&lt;/h4&gt;

&lt;p&gt;So far we know how to write to a stream. If you run the previous code multiple times you find yourself a file that doesn't seem to change at all!&lt;br&gt;
In reality, the file is changing. Every time you execute your code, it's opening a stream to the file, and writing to it starting from the files 0 index until the end of the given byte array. But we often need to also tell the stream &lt;em&gt;where&lt;/em&gt; to start writing or reading data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff90lzmptoygd1d4o79kd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff90lzmptoygd1d4o79kd.png" alt=" " width="475" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every time we open a stream connected to a data source, we're getting the complete ordered list of bytes stored at that source, along with a &lt;strong&gt;&lt;em&gt;pointer&lt;/em&gt;&lt;/strong&gt; to the start of that array. Every operation we execute on the stream moves our pointer in one direction. If we write 10 bytes, we find ourselves 10 positions further down the array than when we started. So, each of our primary operators(&lt;code&gt;Read/Write&lt;/code&gt;) can only ever move in one direction, &lt;em&gt;forward&lt;/em&gt;, from the current stream index when we start executing them.&lt;/p&gt;

&lt;p&gt;for example, if we write to the stream twice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"stream data into a file-"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UTF8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;ioStream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FileStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"strm.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;FileMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OpenOrCreate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result would be the same string twice in a row:&lt;br&gt;
&lt;code&gt;stream data into a file-stream data into a file-&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can make the stream read or write from a certain position in the sequence using the &lt;code&gt;Seek&lt;/code&gt; method on the Stream instance. This makes the stream to seek that index, relative to the given indexes. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;SeekOrigin&lt;/code&gt; enum gives us the three useful origins we might want to use in most cases: &lt;code&gt;Begin&lt;/code&gt;, &lt;code&gt;Current&lt;/code&gt;, &lt;code&gt;End&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example in our previous code, if want to stop overwriting the message every time, and actually append a string to the end of the file every time the program is executed, we can simply make the stream fetch the end of the file and start writing to it from there like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"stream data into a file-"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UTF8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;ioStream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FileStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"strm.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
    &lt;span class="n"&gt;FileMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OpenOrCreate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CanWrite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// set the pointer to the end of the file&lt;/span&gt;
    &lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Seek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SeekOrigin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;End&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

    &lt;span class="c1"&gt;// now write to the stream from the end&lt;/span&gt;
    &lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're telling the stream to first go to the end of the stream, and start it's operation from there:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhy8f1vvrorryr1ymxv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhy8f1vvrorryr1ymxv3.png" alt=" " width="314" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading from streams
&lt;/h3&gt;

&lt;p&gt;Each time the read operation is executed the streams cursor moves forward by one index. Data is read one byte at a time. You have to store the data you read in an array, or a single byte depending on your usage, and you have to make sure the array exists before you read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"stream data into a file"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UTF8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;ioStream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FileStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"strm.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;FileMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OpenOrCreate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CanWrite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;  
    &lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Seek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SeekOrigin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;End&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
    &lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;  
&lt;span class="k"&gt;else&lt;/span&gt;  
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Couldn't write to our data stream."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CanRead&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
&lt;span class="p"&gt;{&lt;/span&gt;  
    &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;destArray&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  
    &lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;destArray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UTF8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;destArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this approach works, there are limitations to it that make the code not-so-clean to work with. There's the issue of using the old-style arrays and their fixed size. It forces you to specify the size of the array, which in hand makes you probably use a reasonable maximum size for the array. &lt;/p&gt;

&lt;h2&gt;
  
  
  Stepping up from Stream
&lt;/h2&gt;

&lt;p&gt;While the base &lt;code&gt;Stream&lt;/code&gt; class opens up a lot of opportunities by giving us meaningful yet simple ways to manipulate streams, a lot of the work is repetitive and tedious most of the times. This is where we move on to more powerful types which ease each process of reading and writing. &lt;/p&gt;

&lt;h3&gt;
  
  
  JSON
&lt;/h3&gt;

&lt;p&gt;before moving to general readers and writers, it's worth mentioning the most famous specification for data transfer around the web, JSON. &lt;br&gt;
In &lt;code&gt;.NET&lt;/code&gt; we have the famous &lt;code&gt;Newtonsoft.Json&lt;/code&gt; which is easy and powerful to work with. &lt;br&gt;
Since &lt;code&gt;.NET Core 3.0&lt;/code&gt;, Microsoft has developed an alternative, &lt;code&gt;System.Test.Json&lt;/code&gt;. the focus of this new JSON library is on performance and fine-grained control over the serialization process. As a result, the feature set of the &lt;code&gt;System.Text.Json&lt;/code&gt; library is severely limited when compared to &lt;code&gt;Newtonsoft.Json&lt;/code&gt;. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;StreamReader&lt;/code&gt; &amp;amp; &lt;code&gt;StreamWriter&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Since most of our work consists of using strings to capsulate complex data with json, it makes sense to have types tailored for working with strings. &lt;br&gt;
The &lt;code&gt;StreamReader&lt;/code&gt; &amp;amp; &lt;code&gt;StreamWriter&lt;/code&gt; classes sub-class the &lt;code&gt;TextReader&lt;/code&gt; class from the &lt;code&gt;System.IO&lt;/code&gt; namespace, and extend its functionality to interface directly with byte streams. &lt;/p&gt;

&lt;p&gt;Even though we're using a &lt;code&gt;FileStream&lt;/code&gt; here for demonstration purposes, for real network programming, we'll want to connect directly to a data stream to a remote resource.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When working with strings from remote resources, knowing the specific encoding with which to translate the incoming bytes is key. If a character is encoded as UTF32, and decoded using ASCII, the result wouldn't match the input, rendering your output string a garbled mess. If you ever find a message that you've parsed to be indecipherable, make sure you're using the right encoding.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Using these classes will reduce the amount of work you need to do when working strings to just a few simple lines (if you know what you're doing!):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;ComplexModel&lt;/span&gt; &lt;span class="n"&gt;testModel&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ComplexModel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;JsonConvert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SerializeObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;testModel&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;ioStream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FileStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"strm.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FileMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OpenOrCreate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;StreamWriter&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StreamWriter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ioStream&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since these classes are designed to work exclusively with string content, they even provide useful extensions, such as a &lt;code&gt;WriteLine(string)&lt;/code&gt; method that will terminate the string you've passed in with a line terminator character. Meanwhile, the &lt;code&gt;ReadLine()&lt;/code&gt; method will return characters from your current index up to and including the next line terminator in the buffer. This isn't terribly useful with a serialized object, since you don't want to read a line of a JSON string. However, if you're working with a plain-text response, it can make reading and writing that response a breeze. &lt;/p&gt;

&lt;h3&gt;
  
  
  Seek vs Peek
&lt;/h3&gt;

&lt;p&gt;Using the reader and writer types don't allow us to set the current index of the stream, for that we have to directly access the underlying stream using their &lt;code&gt;BaseStream&lt;/code&gt; property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"stream test message"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FileStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"strm.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FileMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OpenOrCreate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;StreamWriter&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StreamWriter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;BaseStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Seek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SeekOrigin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;It's not uncommon to forward search through a string until arriving at a terminating character or flag value. Doing so with the &lt;code&gt;StreamReader.Read()&lt;/code&gt; operation will result in moving the index past the terminating character and popping the terminating character off the array. If you want to simply read the last character before the terminating character, though, you have the &lt;code&gt;Peek()&lt;/code&gt; operation. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;Peek()&lt;/code&gt; will return the next character in the array without advancing the current index of the &lt;code&gt;StreamReader&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FileStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FileMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OpenOrCreate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;StreamReader&lt;/span&gt; &lt;span class="n"&gt;sr&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StreamReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Peek&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of the above code is that the stream index will be exactly on the termination character. This also means that the stream is closed and write is unavailable.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;NetworkStream&lt;/code&gt; class
&lt;/h3&gt;

&lt;p&gt;This class behaves exactly the same as the &lt;code&gt;FileStream&lt;/code&gt; class. The only difference being that it's underlying type is an instance of the &lt;code&gt;Socket&lt;/code&gt; class.&lt;br&gt;
All the operations we did on the &lt;code&gt;FileStream&lt;/code&gt; class work on this type as well and it can also be the &lt;code&gt;BaseStream&lt;/code&gt; of an instance of the &lt;code&gt;StreamReader/Writer&lt;/code&gt; classes we've seen. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This type will be important when you want to implement your own socket connections.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most stream operations have &lt;strong&gt;&lt;em&gt;concurrent&lt;/em&gt;&lt;/strong&gt; variations as well. This greatly improves the performance of your application since some stream operations will be heavy and time consuming.&lt;/p&gt;

&lt;p&gt;An example of how to work with networks using the stream types that we've learned so far with their concurrent counterparts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;PostRequestAsync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WebRequest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://test-domain.com"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

    &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;Stream&lt;/span&gt; &lt;span class="n"&gt;reqStream&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetRequestStream&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  

    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;StreamWriter&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StreamWriter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reqStream&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Our test data query"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;webResponse&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetResponseAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  

    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;StreamReader&lt;/span&gt; &lt;span class="n"&gt;sr&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StreamReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;webResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetResponseStream&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RequestResult&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;sr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadToEndAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;This concludes the basic stream foundations that we'll need when working with networks in &lt;code&gt;.NET&lt;/code&gt;, There are other types that inherit &lt;code&gt;Stream&lt;/code&gt; and are for other purposes, but I'm sure by now you've understood that all those types do, only convenients working with the basic underlying &lt;code&gt;Stream&lt;/code&gt; type (just like we saw with &lt;code&gt;StreamReader/Writer&lt;/code&gt; for &lt;code&gt;string&lt;/code&gt;s).&lt;/p&gt;

&lt;p&gt;There are other types that are specifically made for working with files and directories, but you can go and see their implementations, it all comes from streams. &lt;/p&gt;

&lt;p&gt;I hope I could give some useful context to you!&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>streams</category>
      <category>networkprogramming</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Intro to The Network Programming Series</title>
      <dc:creator>Mazdak Parnian</dc:creator>
      <pubDate>Thu, 06 Nov 2025 13:58:52 +0000</pubDate>
      <link>https://dev.to/purejoymind/intro-to-the-network-programming-series-37n6</link>
      <guid>https://dev.to/purejoymind/intro-to-the-network-programming-series-37n6</guid>
      <description>&lt;p&gt;Working with networks always seems intimidating, specially when starting out. From my earlier days a software developer, networking concepts seemed difficult to get around. Even after I took a &lt;code&gt;Network+&lt;/code&gt; course to understand the fundamentals of networking, it was the development side of things that had me sweating. Like all things difficult, I tend to jump in hot instead of running away! &lt;br&gt;
So I searched around and found myself a book, &lt;strong&gt;&lt;em&gt;"Hands-On Network Programming with C# and .NET Core"&lt;/em&gt;&lt;/strong&gt; by &lt;strong&gt;Sean Burns&lt;/strong&gt;. The name pretty much explains the book. I wanted something to show me .NETs capabilities with networks and the book seemed like a great start to that.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Network Programming?
&lt;/h2&gt;

&lt;p&gt;By now there's a chance that some of you are wondering, what really is network programming? &lt;br&gt;
At first it might sound like some guru sort of coding! But what it really means is writing programs that utilize your Operating Systems networking capabilities and allow you to control them to your benefit. &lt;br&gt;
Any sort of program that uses a network falls under that category; things like setting up a lan, using FTP to transfer files, using a GET HTTP Request to get some data from a server, the list goes on. There's a really good chance that you've done some sort of network programming without even knowing the term! &lt;br&gt;
As backend developers, our work involves setting up networks most of the time, more specifically, setting up HTTP servers and providing/consuming resources over the network. &lt;br&gt;
It bothered me that I felt like I was using some blackbox to setup my servers. I like knowing what's happening under the hood. Plus, it's not just about knowing! There's a lot of things that the framework offers that you can use to solve your challenges and knowing more never hurts.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is This Series?
&lt;/h2&gt;

&lt;p&gt;One thing about learning (niche) topics like this, is that you most definitely will forget some parts. Not that it's a bad thing, there's just too much information and it's mostly good to know what exists and look for details on it later. &lt;br&gt;
So I thought I'd start a series on the topic, keep things organized so I can find the important stuff later again, and also share the good stuff with YOU! &lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;While the book firstly covers networking basics and concepts, I don't want this to be the book. If you really have no idea what networks are, or what's an IP, or protocols like HTTP or similar topics, the series would probably confuse you more and I suggest you read on networking fundamentals. There are great sources for that on the internet in any form you prefer, or you can simply read the book I mentioned earlier, it covers all the concepts one needs to know to get started with networks.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I'll Cover
&lt;/h3&gt;

&lt;p&gt;I want to cover the practical side of networking. Mostly how .NET does things and how to work with the tools the framework offers. Some examples could include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Streams&lt;/li&gt;
&lt;li&gt;Sockets &amp;amp; Ports&lt;/li&gt;
&lt;li&gt;FTP&lt;/li&gt;
&lt;li&gt;TCP &amp;amp; UDP&lt;/li&gt;
&lt;li&gt;Security&lt;/li&gt;
&lt;li&gt;Analysis &amp;amp; Packet Inspection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the sort of topics that interest me and they are why I decided to dive deep in networks! I hope you also find the series useful! Be sure to keep in touch if you have any suggestions or questions!&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>networking</category>
      <category>networkprogramming</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Learning Go as a .NET Developer</title>
      <dc:creator>Mazdak Parnian</dc:creator>
      <pubDate>Fri, 08 Aug 2025 16:27:10 +0000</pubDate>
      <link>https://dev.to/purejoymind/learning-go-as-a-net-developer-38mp</link>
      <guid>https://dev.to/purejoymind/learning-go-as-a-net-developer-38mp</guid>
      <description>&lt;p&gt;I've been a .NET developer for 3 years now. Throughout my journey I've learned so much, and at the same time, I've had a lot more questions. The .NET ecosystem is big and mature, but the learning curve is also noticeable.  From the C# language itself to the ASP.NET Core framework and all the tools one needs to know like Entity Framework. Sometimes I wondered if other languages have this much to offer as well. I've always been a practical hands-on type of person. I like to know how things work, and how I can make them better. &lt;br&gt;
One of my favorite things to do is having technical discussions with my developer friends. Talking about how things work, interesting challenges we've faced, fun things we've done, etc. One of them is a Go developer. Before talking to him, I knew of Go, but I had no idea what it looked like. But very quickly it got my attention. &lt;br&gt;
&lt;em&gt;I liked the core philosophy of the language, **Simplicity&lt;/em&gt;&lt;em&gt;.&lt;/em&gt; &lt;br&gt;
The Go programming language aims to keep things simple all the while giving you the power to do anything you want. Anything you can do in C#, you can do in Go. &lt;/p&gt;

&lt;p&gt;You can check the language out &lt;a href="https://go.dev/" rel="noopener noreferrer"&gt;here&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;I studied &lt;a href="https://www.gopl.io/" rel="noopener noreferrer"&gt;The Go Programming Language&lt;/a&gt; book. It's an amazing starter book. you can find it here!&lt;/p&gt;
&lt;h2&gt;
  
  
  Memory Management &amp;amp; Garbage Collection
&lt;/h2&gt;

&lt;p&gt;While learning about memory management in Go, I realized how similar it is to C#. Both languages use a garbage collector. &lt;br&gt;
C# has reference types and Go has safe pointers. At first glance they looked and felt like each other. Both reference types and safe pointers aim to cover the un-safety of pointers. They actually behave quite similar. &lt;br&gt;
In Go whenever you want to pass a reference you simply pass a pointer to the variable, and the pointers can be &lt;code&gt;nil&lt;/code&gt;, Go's &lt;code&gt;null&lt;/code&gt; construct.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// C#&lt;/span&gt;
&lt;span class="nf"&gt;SomeMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// classes are reference types by default&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="n"&gt;someMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// looks like c-based pointers, but it's safe!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;Go functions can return multiple values by default. In C# it's kind of similar to using &lt;code&gt;Tuples&lt;/code&gt; but it's not exactly the same, but looks like it. Since it's part of Go it allows the developers to use "The Result Pattern". We'll talk about this more in "Error Handling".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// C#&lt;/span&gt;
&lt;span class="c1"&gt;// using Tuples to return multiple values&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;SomeMethod&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="c"&gt;// returning multiple values&lt;/span&gt;
&lt;span class="n"&gt;SomeMethod&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v2&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Go, the returned types come after the parameter list of the function, unlike C#. &lt;br&gt;
You might have also noticed that the type of the variables come after their identifier in Go!&lt;/p&gt;
&lt;h2&gt;
  
  
  The Compiler
&lt;/h2&gt;

&lt;p&gt;The compiler is where Go shines more than C# in my opinion. The compiler acts as a major safeguard here. A lot of the bugs show up at compile-time. The language doesn't have a JIT compiler unlike C#. Go uses the compiler to enforce the syntax in a stricter manner. &lt;br&gt;
For example, your variables must be used otherwise that's a compiler error. This helps a lot with removing unnecessary memory allocation. Returned variables from functions must be used or explicitly discarded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="n"&gt;SomeMethod&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="n"&gt;SomeMethod&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// compiler error! returned values not used!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I feel safer and more comfortable with Go's compiler. &lt;/p&gt;

&lt;h2&gt;
  
  
  Concurrency
&lt;/h2&gt;

&lt;p&gt;C#'s concurrency model, is vast. You have multiple ways to make something concurrent. each one has it's own challenges and merits. More importantly it requires you to know it well before using it. While it's a powerful system, it can be daunting to start with. It took me some time to get used to and learn beyond &lt;code&gt;async/await&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;One of the very first things that caught my eye when I started learning GO was it's concurrency system.&lt;br&gt;
Go has a CPS-Style (communicating sequential processes) concurrency model. What does that mean? &lt;a href="https://en.wikipedia.org/wiki/Communicating_sequential_processes" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt; says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;communicating sequential processes is a formal language for describing patterns of interaction in concurrent systems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://dev.to/karanpratapsingh/csp-vs-actor-model-for-concurrency-1cpg"&gt;This&lt;/a&gt; short article is useful as well if you are interested.&lt;/p&gt;

&lt;p&gt;You can learn Go's concurrency patterns effectively using &lt;a href="https://www.concurrency.rocks/" rel="noopener noreferrer"&gt;Concurrency.Rocks&lt;/a&gt;! &lt;br&gt;
Due to how big this topic is, I'll link to the website rather than showing code here, It's a much better learning material for this topic!&lt;/p&gt;

&lt;h3&gt;
  
  
  Goroutines
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.concurrency.rocks/tutorials/basic-goroutines" rel="noopener noreferrer"&gt;Goroutines&lt;/a&gt; are lightweight concurrency constructs which allow one to run functions in the background. The syntax is straightforward, any function you want to run in the background, simply put the &lt;code&gt;go&lt;/code&gt; keyword behind its call. No more &lt;code&gt;async/await&lt;/code&gt;, no more &lt;code&gt;Task&lt;/code&gt; or &lt;code&gt;Thread&lt;/code&gt;. It simply does what it should. You don't need to worry about threadpools, creating manual threads, using &lt;code&gt;TaskCompletionSource&lt;/code&gt;, none of that. &lt;br&gt;
A notable thing about goroutines is that you can't have them return something. To get a value from a goroutine, you have to use Channels, another interesting GO construct. &lt;/p&gt;

&lt;h3&gt;
  
  
  Channels
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.concurrency.rocks/tutorials/channels" rel="noopener noreferrer"&gt;Channels&lt;/a&gt; are something that you'll face early when learning the language. Channels are another concurrency construct. They allow use to safely pass data in our program in a thread-safe manner. Think of channels as an in-memory message queue. While there's more to it, this isn't a Go tutorial so I won't be showing too much syntax.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error Handling
&lt;/h2&gt;

&lt;p&gt;Handling errors is also one of the thing's where the two languages differ from each other significantly. &lt;br&gt;
C# and other C-Based languages mainly use exceptions to handle error. There's been a lot of discussions about the performance of exceptions in recent years. Go uses something called the "Result Pattern" in the world of software. What that means is that it basically returns whether the function resulted in an error or not. Though this isn't a syntax only for errors. &lt;br&gt;
In the Functions section we talked about returning multiple values from functions. Well, by convention, there are two types of fault handling we can have: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Returning a &lt;code&gt;bool&lt;/code&gt; value named &lt;code&gt;ok&lt;/code&gt; as the last returned value
&lt;code&gt;SomeMethod() (v1 int, ok bool)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Returning an &lt;code&gt;error&lt;/code&gt; which is a struct in the standard go package
&lt;code&gt;SomeMethod() (v1 int, e error)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both of these methods are used regularly in Go programs. This reduces a lot of the performance problems with exceptions while making sure one point stands throughout your program:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A good program knows whether it'll return an error or not. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Exceptions are unknown. Specially when you have a global &lt;code&gt;catch(Exception e)&lt;/code&gt;. A good program should know what types of errors, if any it'll return and handle it gracefully, Go emphasizes on this. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Go?
&lt;/h2&gt;

&lt;p&gt;Now you might think, where would I use Go? For me, .NET is still the language to write my Apis in. The ecosystem is just too mature, and having put the time in to learn it, it's actually quite enjoyable to develop applications in .NET. Each language is a tool and each one has strengths in it's own place. &lt;br&gt;
Go's simple yet effective concurrency model makes it the perfect tool to handle a lot of calls for simple methods, while C# is more focused on delivering business quality allowing one to develop complex businesses. I don't like the feeling of being too dependent on one language. &lt;/p&gt;

&lt;h3&gt;
  
  
  Go is a Modern Language
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;It was designed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson, and publicly announced in November of 2009. - Wikipedia&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go learned a lot from it's predecessors. It aims to please with it's powerful simplicity. One thing which caught my attention about the language was that it felt "low-level" while still being a "high-level" language. But maybe that's just me comparing the syntax to C#. &lt;/p&gt;

&lt;p&gt;Not having a Just-In-Time compiler also means it's much easier to build your program for different OS, Although not that it matters anymore since .NET has become cross-platform recently. But that still makes the executables more lightweight and easier to port. I would actually prefer writing system programs, cli tools and other similar type of programs in go instead of .NET, it just feels right with Go.&lt;/p&gt;

&lt;p&gt;Another way learning Go has helped me, was making me deepen my knowledge in C#. When studying the language, I often questioned myself on how I would achieve the same result of a program in each language. One example was Channels. I quickly realized that C# also has channels and that it was added in  .NET Core.  I remember how happy and excited I was! &lt;br&gt;
By learning how two or more languages approach the same challenges and problems, one can develop better software knowing what happens underneath all the cute interfaces and Apis. Languages and frameworks are tools one learns to apply. We often forget why we learn programming. To solve problems. Just because you know one language doesn't mean you can't learn another. Software development is all about depth and perspective! &lt;/p&gt;

&lt;p&gt;I hope this gave you some insight to the Go Programming language and maybe it made you want to try it out! &lt;/p&gt;

</description>
      <category>go</category>
      <category>csharp</category>
      <category>todayilearned</category>
      <category>resources</category>
    </item>
    <item>
      <title>Making a Thread-Safe Cache in .NET</title>
      <dc:creator>Mazdak Parnian</dc:creator>
      <pubDate>Mon, 21 Jul 2025 10:20:43 +0000</pubDate>
      <link>https://dev.to/purejoymind/making-a-thread-safe-cache-in-net-20aa</link>
      <guid>https://dev.to/purejoymind/making-a-thread-safe-cache-in-net-20aa</guid>
      <description>&lt;p&gt;One of the challenges that we will face as a developer is the problem of accessing a resource from multiple threads. Handling concurrency and shared state between different threads is a delicate and important feat. &lt;br&gt;
Today we'll look into the problem of accessing a Cache/Dictionary in a thread safe way. &lt;/p&gt;
&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;suppose we have a cache that holds data that we fetch from another server. A consumer calls the cache to fetch data for a key, and if the cache doesn't have the data, it must download it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DataModel&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_cache&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DataModel&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetValueAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_cache&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;DownloadDataAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach is generally fine and thread-safe and we don't need locking for safety. Until two threads try to get the same key value from the cache. In that case there will be multiple download requests for the same data, each updating the same cache entry. While this still won't cause an error, it can affect performance. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;The solution is interesting and easy. Instead of keeping the value directly in the cache, we keep it's future. So the cache holds &lt;code&gt;Task&amp;lt;DataModel&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DataModel&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_cache&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DataModel&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetValueTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;dataTask&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dataTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_cache&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;DownloadDataAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, we'll always get the same &lt;code&gt;Task&lt;/code&gt; for each &lt;code&gt;DataModel&lt;/code&gt; if we call the &lt;code&gt;GetValue&lt;/code&gt; method with the same key over and over, and if the Task is complete awaiting it has low cost. This approach also reduces the load on the Garbage Collector.&lt;br&gt;
Notice that we're not using the &lt;code&gt;async/await&lt;/code&gt; keywords here since we need to return the tasks themselves not the actual value. &lt;/p&gt;

&lt;p&gt;To make it truly thread-safe we lock the operation. Though the lock will be very short since we're only locking for the duration of a lookup and quick add to the cache, since the actual downloading will be done inside the &lt;code&gt;Task&lt;/code&gt; and not in the &lt;code&gt;GetValueTask&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DataModel&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_cache&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DataModel&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetValueTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_cache&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;dataTask&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dataTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_cache&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;DownloadDataAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although there are ready-made constructs to achieve similar designs, it's important to understand the underlying techniques used in their making. &lt;/p&gt;

&lt;p&gt;I hope this helps! Ask me any questions you might have about concurrent caches!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>concurrency</category>
      <category>cache</category>
      <category>lock</category>
    </item>
    <item>
      <title>I Created a .NET 8 Web Api Project Template</title>
      <dc:creator>Mazdak Parnian</dc:creator>
      <pubDate>Fri, 01 Mar 2024 12:01:58 +0000</pubDate>
      <link>https://dev.to/purejoymind/i-created-a-net-8-web-api-project-template-4mno</link>
      <guid>https://dev.to/purejoymind/i-created-a-net-8-web-api-project-template-4mno</guid>
      <description>&lt;h2&gt;
  
  
  Introducing My Web API Project Template: A Time-Saver for .NET Developers
&lt;/h2&gt;

&lt;p&gt;Are you tired of spending hours setting up a new Web API project from scratch? I know I was. That's why I decided to create a project template that includes all the essential features I need for my Web API projects. This template is designed to save you time and ensure a smooth development workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Template?
&lt;/h2&gt;

&lt;p&gt;I am sure there are lots of project templates out there which make setting up new projects faster and easier. But I also have a habit of doing things for myself. So When I had to setup a Web API project in .NET 8, it took a while to setup all my desired features.&lt;/p&gt;

&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;p&gt;Setting up a Web API project in .NET 8 can be a daunting task, especially when you want to include specific features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Entity Framework Core for robust data access&lt;/li&gt;
&lt;li&gt;Swagger with API versioning for easy API documentation and testing&lt;/li&gt;
&lt;li&gt;NLog for comprehensive logging&lt;/li&gt;
&lt;li&gt;SignalR for real-time communication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've spent some time configuring and testing these features to ensure they're development-ready. Now, I'm sharing this template with you to help streamline your project setup process.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use the Template
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt;: I have created and tested this template in &lt;code&gt;Visual Studio 2022 version 17.8&lt;/code&gt;. It should work in version &lt;code&gt;&amp;gt;17.0&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download the Template: Visit the GitHub &lt;a href="https://github.com/PureJoyMind/ApiSetupProjectTemplate" rel="noopener noreferrer"&gt;Repository&lt;/a&gt; of the template project.&lt;/li&gt;
&lt;li&gt;Get the Template File: Download the template file from the Release section of the repository.&lt;/li&gt;
&lt;li&gt;Copy the Template file to &lt;code&gt;C:\Users\{User}\Documents\Visual Studio 2022\Templates\ProjectTemplates&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create A new Project and select the template from the list of templates. If you don't see the template search for it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabjtzqx7yvmfqgwk2j03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabjtzqx7yvmfqgwk2j03.png" alt="Create New Project in Visual Studio 2022" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Customize and Use
&lt;/h3&gt;

&lt;p&gt;Feel free to customize the template to fit your project's needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need Help or Want to Contribute?
&lt;/h2&gt;

&lt;p&gt;I'm always open to feedback and contributions. If you have any suggestions for improvements or encounter any issues with the template, please don't hesitate to contact me.&lt;/p&gt;

</description>
      <category>api</category>
      <category>dotnet</category>
      <category>template</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A Friendly Intro To Software Documentation</title>
      <dc:creator>Mazdak Parnian</dc:creator>
      <pubDate>Tue, 09 Jan 2024 17:44:28 +0000</pubDate>
      <link>https://dev.to/purejoymind/a-friendly-intro-to-software-documentation-2l4c</link>
      <guid>https://dev.to/purejoymind/a-friendly-intro-to-software-documentation-2l4c</guid>
      <description>&lt;p&gt;Documents are such an underrated thing. We all love good documentation when we see one, but when it comes to writing our own documentation, that's where it gets tricky!&lt;br&gt;
Today we're going to discuss documentation, its role in software and development, and why it's better to spend company resources to create and maintain it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Documentation?
&lt;/h2&gt;

&lt;p&gt;There has always been a love-hate relationship between developers and documentation. We love it when we consume it, and it's the most difficult thing to make at the same time. Because everybody knows, right? Or, good code documents itself. We've all heard these infamous lines somewhere down the road. Maybe at some point, we thought to ourselves, "Well, the code I have written seems pretty easy. How can someone not understand this?"&lt;br&gt;
While that may be true in some cases, it often causes more trouble than it seems.&lt;br&gt;
Documentation helps keep track of where the project is headed while preserving its current and past state.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project
&lt;/h3&gt;

&lt;p&gt;There are many stages in the project's lifetime. Some of them can include meetings with the stakeholders. Documents help clearing the air by providing transparency about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The project&lt;/li&gt;
&lt;li&gt;Where it is headed&lt;/li&gt;
&lt;li&gt;Its current state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It eases the process of change in the project, which can be a change of managers, features, developers, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Development
&lt;/h4&gt;

&lt;p&gt;Developers use documentation all the time. You don't have to be a major company to use documents. Suppose you are a small team of developers with a few people in each section (front-end, back-end, infrastructure, etc.). Having documentation in each section helps other teams manage their work with less entanglement between people.&lt;br&gt;
John doesn't have to call Ellis to ask about the project APIs or ask for a sample request to call a service. With proper documentation, he can simply look up the documentation for that service and get most of the data he needs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Speeding Up Recruitment
&lt;/h4&gt;

&lt;p&gt;It's much faster and easier to read documentation about something rather than having to look for someone to explain it. When there are new employees in the company, it is very convenient to have them read the documentation because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It saves company resources. This way, the company doesn't need to assign another employee to get the newcomers up to date with everything.&lt;/li&gt;
&lt;li&gt;It is up-to-date with the company's projects and latest developments.&lt;/li&gt;
&lt;li&gt;It has enough information a newcomer needs to get started.&lt;/li&gt;
&lt;li&gt;It allows them to get familiar with the working environment and how projects are handled in the company.&lt;/li&gt;
&lt;li&gt;It can be a faster approach because people might learn faster if they do it at their own pace.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gz6r2ef2le7i1za75tq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gz6r2ef2le7i1za75tq.jpg" alt="board-with-stickers" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Make Better Documents
&lt;/h2&gt;

&lt;p&gt;Now that we know why we should use documents, there are a few things we can keep in mind to make better documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implement Documentation in your Development Cycle
&lt;/h3&gt;

&lt;p&gt;Starting documentation for a project can be a huge thing. Specially if the project has been going on for some time. The first thing to understand is that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Documentation is a part of software development.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So don't think little of it. It is something that needs its own dedicated time during development, and for good reason. So don't think that it is something that can be done in a few days, and you're done. No.&lt;br&gt;
In order to have useful and effective documentation, you need to implement it in your development cycles/sprints/iterations. Dedicate a part of your company's employees time to documentation, and don't make it sound unimportant. Sure, you'd like to get that feature done quickly, but you also need to have that feature documented so the next person working on it can have an easier time developing it. &lt;/p&gt;

&lt;h3&gt;
  
  
  Think Outside the Box
&lt;/h3&gt;

&lt;p&gt;I was reading a book on software documentation. It mentioned something very important when writing software documentation, &lt;strong&gt;&lt;em&gt;The Curse Of Knowledge&lt;/em&gt;&lt;/strong&gt;. When you are writing documentation about something, you have a certain level of understanding about it. You don't need to be the master of that thing, just enough to make others understand too. But when we are transferring knowledge, we tend to forget that other don't know. &lt;br&gt;
"It's such an easy thing; how can someone not get it?"&lt;br&gt;
But we easily forget the amount of energy and time we put into learning something. So it's easy to overlook important things in the document and miss out on a few things here and there. These things add up, and suddenly we find ourselves with a piece of vague documentation that creates more questions than it answers.&lt;br&gt;
In order to avoid this tricky situation, here are some things you should consider before writing documentation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who are you writing the document for?&lt;/li&gt;
&lt;li&gt;What is their level of knowledge? What is the prerequisite for this document?&lt;/li&gt;
&lt;li&gt;What kind of information are you trying to transfer? Is it a tutorial? a reference? a starting guide?&lt;/li&gt;
&lt;li&gt;What can the audience do wrong? for example, if they click on another button, fill out the wrong form, or enter the wrong information? Keep everything in mind.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fikn7m6u9uxjbar1z99nh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fikn7m6u9uxjbar1z99nh.jpg" alt="overthinking" width="800" height="1000"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Don't Overthink It
&lt;/h3&gt;

&lt;p&gt;Writing documentation is not rocket science. However, it easily gets overwhelming when we think about all the things we want to write. It's important to write just the right amount of documentation, but at the same time, it can get out of hand very quickly. Try to have your documents reviewed by multiple people, like the audience you are writing for.&lt;br&gt;
For example, if you are writing documents for a customer, have them read them and tell you if they have any problems with them. Or have someone who knows the topic read it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Feedback always helps.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Try not to bombard the reader with too much information. Keep it just enough, but don't forget the edge cases of what they should know and should not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;While writing software documents can be a slow and boring task for many, it is almost always worth it. Don't let anyone tell you otherwise. It can cost you, but developing good software comes with costs.&lt;br&gt;
I hope this article has helped you find your way with documents.&lt;/p&gt;

</description>
      <category>documentation</category>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
      <category>development</category>
    </item>
    <item>
      <title>The Start Of My Blogging Journey</title>
      <dc:creator>Mazdak Parnian</dc:creator>
      <pubDate>Sun, 17 Dec 2023 12:47:30 +0000</pubDate>
      <link>https://dev.to/purejoymind/the-start-of-my-blogging-journey-45on</link>
      <guid>https://dev.to/purejoymind/the-start-of-my-blogging-journey-45on</guid>
      <description>&lt;p&gt;I have been thinking about doing this for a long time now. There are many reasons as to why I wanted to do this. I'll get to them shortly. But first, a little about me. I have to let you,  the readers of this very first post, know who I am and what you are doing here.&lt;/p&gt;

&lt;h1&gt;
  
  
  Who Am I?
&lt;/h1&gt;

&lt;p&gt;I am a junior software developer from middle east. I have started my professional career for a little over a year now. But this wasn't my first contact with the world of IT. &lt;br&gt;
I started getting interested in IT at highschool. I started learning Python and soon my path crossed with the world of Linux. But for a long time I didn't do anything major or think about this as my career in a way I should've. But still I chose Software Engineering as my bachelors topic. This just made me fall more in love with the world of computers.&lt;br&gt;
currently I am still a student. But soon I will finish my bachelors degree. &lt;/p&gt;

&lt;h2&gt;
  
  
  My Skills
&lt;/h2&gt;

&lt;p&gt;I am a &lt;code&gt;.Net&lt;/code&gt; developer. But I wasn't always on &lt;code&gt;.Net&lt;/code&gt;. &lt;br&gt;
My career started as a &lt;code&gt;NodeJs&lt;/code&gt; developer. But soon I realized I wanted to be a professional in a language that has a huge company backing it and is frequently used in major organizations and such. There is absolutely nothing wrong with being a &lt;code&gt;NodeJs&lt;/code&gt; developer and generally, its just a matter of preference. But for me the switching to &lt;code&gt;.Net&lt;/code&gt; was the perfect choice. &lt;br&gt;
I am also good at working with Databases. I have taken a deep course on &lt;code&gt;MSSQL&lt;/code&gt; server. But I also have worked with &lt;code&gt;MongoDB&lt;/code&gt; from the days I was hired as a &lt;code&gt;NodeJs&lt;/code&gt; Developer. &lt;br&gt;
I have a deep love for Linux systems. This goes a little opposite ways since &lt;code&gt;.Net&lt;/code&gt; is a Microsoft product and works best with windows servers. But still, I feel most comfortable when I am working with a Linux server. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftq4tqz0puq0qv80negzx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftq4tqz0puq0qv80negzx.jpg" alt=" " width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Job
&lt;/h2&gt;

&lt;p&gt;I started my first &lt;code&gt;.Net&lt;/code&gt; job about 6 months ago. It was just after I finished my second project in &lt;code&gt;C#&lt;/code&gt;. I started learning &lt;code&gt;C#&lt;/code&gt; just after the new year holidays in my country. before the new year I quit my &lt;code&gt;NodeJs&lt;/code&gt; job because I didn't see a future in it for me and I felt like I wasn't a good enough backend developer. &lt;br&gt;
So I started learning &lt;code&gt;C#&lt;/code&gt; with a course. Then I finished a course on &lt;code&gt;.Net 6&lt;/code&gt; and &lt;code&gt;MVC&lt;/code&gt; and then I quickly finished a course on Authentication and Authorization in &lt;code&gt;.Net&lt;/code&gt;. this all took about 2 months for me. Thus began the time to send resumes. It took a month or two for me to find a job. I was very inexperienced. But I had confidence. &lt;br&gt;
My first job as a &lt;code&gt;.Net&lt;/code&gt; developer was found after some time. I am still working there and I am very happy about the place I work. &lt;br&gt;
I develop and extend Microsoft Dynamics 365/CRM solutions with  &lt;code&gt;.Net&lt;/code&gt;. It took me a month or two to finish my training in D365, and I continue to learn more about it everyday at work.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why Blogging?
&lt;/h1&gt;

&lt;p&gt;Since my first days of getting to know the world of computers until now, I have had a deep passion for teaching all the cool things I have read. I have considered creating a course multiple times. But creating courses or video content for Youtube takes a lot of time and dedication. So I thought, if I zoom out of video content, I have podcasts and blogs. It sounded like a wonderful idea to me. It lets me put less time into content creation all the while giving back the knowledge I have gained to the world. &lt;/p&gt;

&lt;h2&gt;
  
  
  What It Gives Me
&lt;/h2&gt;

&lt;p&gt;Another reason for creating such content is that it allows me to track my own progress like a sort of journal. It lets me compare myself to my past and see where I have come from. &lt;br&gt;
Also, I think it would be a good idea to also create content that non-tech people can benefit from. After all this is the age of technology and almost all people need to have a basic understanding of computers. &lt;br&gt;
I enjoy explaining my work and things I learn to my non-tech friends and this blog gives me a channel to direct my energy to. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz5b7wquybiqm20h0tv62.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz5b7wquybiqm20h0tv62.jpg" alt=" " width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How It Inspires Me
&lt;/h2&gt;

&lt;p&gt;Thinking about explaining things, has always made my brain engines start. There's that famous saying which tells us we will only have learned something when we can transfer that knowledge, which at least goes very true for me. &lt;br&gt;
Another reason which creating content helps me is that it makes me want to learn more myself, so I can teach more. Throughout the day, at work or at university, I hear a lot of useful stuff like new technologies, news, the right way to do something, and many other peoples experiences. All of those inspire me to transfer them in my content and give back to the community. &lt;br&gt;
After all, the world of technology has only improved because of its communities contribution.&lt;/p&gt;

</description>
      <category>firstpost</category>
      <category>webdev</category>
      <category>career</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
