Posts

Showing posts from May, 2023

Common keyword terms and concepts in C# programming

  Here are some common keyword terms and concepts in C# programming: Variable: A named storage location that holds a value of a particular data type. Data Type: The type or category of data that a variable can store, such as integer, string, Boolean, etc. Class: A blueprint for creating objects that define their properties (data) and behaviors (methods). Object: An instance of a class that represents a specific entity or concept and encapsulates its state and behavior. Method: A block of code that performs a specific task or action. Parameter: A variable used in a method to receive values from the caller. Return Type: The data type that specifies the type of value returned by a method. Conditional Statement: A statement that allows the program to make decisions based on certain conditions, typically using keywords like if, else, and switch. Loop: A control flow statement that repeats a block of code until a specific condition is met, using keywords like for, while, and do-while. Ar...

Demonstration: Serializing Objects as JSON in C# using JsonSerializer and JsonConvert

In this demonstration, you will see how to serialize and deserialize objects using JsonSerializer and  JsonConvert In the example below, we have a Person class with Name and Age properties. We create an instance of the Person class with some values. Then, we use JsonSerializer.Serialize to convert the object to a JSON string.  Next, we print the serialized JSON string to the console. After that, we use JsonSerializer.Deserialize to convert the JSON string back into an instance of the Person class. Finally, we print the properties of the deserialized object to verify that the serialization and deserialization process worked correctly. Make sure to include the System.Text.Json namespace in your code to access the JsonSerializer class and related types. using System ; using System . IO ; using System . Text . Json ; namespace SerializationDemo {     public class Person     {         public string Name { get ; set ; }   ...

Implicit and Explicit Interface Implementation in C#

 Attention programmers! Are you looking to create loosely-coupled and contract-based designs in C#? Look no further than the interface! With signatures for methods, properties, indexers, and events, an interface allows for implementation in a separate class. And the best part? C# does not support "multiple inheritances" (a class can only inherit from one base class). However, it can be achieved with interfaces, because the class can implement multiple interfaces! But wait, there's more! Implementing interface members implicitly is the most common method, allowing for flexibility in where the method is declared. Don't miss out on the benefits of using interfaces in your C# programming. Try it out today! Implicit interface implementation This is the most regular or obvious way to implement members of an interface. Here we don't specify the interface name of the members and implement implicitly. The method can be declared at any interface (s) the class implements. in...