C# Tutorial

Hello everyone, I hope you all are fine and having fun with your lives. Today, I am going to share the list of all the C# tutorials, which I have posted on my blog till now. So, this post will be like a complete C# tutorial, which will have all the small and big C$ tutorials, I have posted on my blog. This list is quite small right now but I will post more C# tutorials soon and will add their links here. Actually, the C# tutorials are quite random on the blog so I am kind of compiling the list and pasting them all here so that readers won't get into much trouble finding them.

Till now, I have mostly posted the project on our blog in which I don't teach any language but provide you the code for that project. But now I have thought of writing complete series of tutorials in which I will teach different languages to beginners. I hope you will find them really helpful. So, the C# tutorial is the first tutorial in this series. I will post tutorials on other languages soon. So, let's get started with the C# tutorial:

C# Tutorial

Here are some very basic C# Tutorial, which are just for the beginners and if you know the basics of C# then I would suggest you to skip this section:

Basic Tutorials:

Note:

Loops in C#:

Important Concepts in C#:

C# Windows Form

Data Types in C#

Tutorials on C# Controls

Tutorials on C# Loops

Thanks for reading all those tutorials. If you still have any questions then ask in the comments and we will try our best to resolve your issues. Take care and have fun !!! :)

How to use Button in C# Windows Form ?

Hello everyone, I hope you guys are having fun with your lives. In today's tutorial, we are gonna have a look at How to use Button in C# Windows Form. In our previous tutorials, we have first discussed the Introduction to C# Windows Forms in which we have created our first C# Windows Forms Project. After that we have discussed How to add C# Controls in Windows Form, in which we have added different C# controls in that Windows form.

So, now we are gonna add back end programming in those Controls one by one. In today's tutorial, I am gonna add the code for the Buttons and you will see that it won't be any difficult to use them in your projects. So, let's get started with How to use Button in C# Windows Form.

How to use Button in C# Windows Form ???

  • So, now we have two buttons in our C# Windows Form, so now First of all, let's change the text of first button from its Properties as shown in below figure:
  • So, I have changed the text of Button1 to Click Here and I am gonna change the text of Button2 to Submit and they will now look like something as shown in below figure:
  • Now you can see in the above figure that the Text on these buttons have changed to that which I have added in the Text section of their properties.
  • Moreover, you must have also noticed that now their size has also increased, which I did by dragging the buttons.
  • Now let's change the name of these buttons too so I am gonna change the Name of first button to ClickHere and that of second button to Submit.
  • We can't add spaces in the Name of the Button.
  • The Name Change for first button is shown in below figure:
  • Now let's add the Click event for each of these buttons.
  • Click event is the event which should happened when you press the button.
  • So, now double click the first button and it will open up its code as shown below:
  • Now you can see in the above code we have a function named ClickHere_Click, which is the click event function for first button.
  • ClickHere is the name of the button which we changed above and _Click is the event. In simple words, this event will call on when the ClickHere Button is clicked.
  • Next we have the arguments, which I am not currently gonna discuss here but we will have a look at them later and then we have these curly brackets { }, and that's where our code is gonna pasted for the click event of this button.
  • So, add the below code into these brackets.
MessageBox.Show("Its a Click Here Button");
  • Now when you pressed the Click Here Button then a sall message box will open up as shown in below figure:
  • So, now you have seen, first we have added the Button then we changed its Text and Name and later we added the back end code in it so that it could perform an event on clicking.
  • Now, I have added a small code in the Submit Button Click event and it looks something like this when you click it:
  • So, that's all about how to use button in C# Windows Form.
That's all for today. Will meet you guys in the next tutorial on C#. Till then take care and have fun!!! :)

How to Add C# Controls in Windows Form ???

Hello everyone, hope you all are fine and having fun with your lives. Today, I am going to show you How to add C# Controls in your project. In our previous tutorial, we have seen an Introduction to C# Windows Forms in which we have created our first project and then we have discussed all about its different features like How to use Properties etc. and if you haven't read it yet then I would suggest you to read that one first as I am gonna continue from that tutorial onward.

So, I am assuming that you have read Introduction to C# Windows Forms and you have your first project created and ready to use. So, if you have dne exactly as I have shown in my previous tutorial then you have a for as shown in the below figure:

So, now we are gonna add some C# controls in this Windows form. So, let's get started with How to add C# Controls in it.

How to add C# Controls ???

  • In our previous tutorial, we have discussed the Toolbox, which is available on the left side of your project.
  • All the components in the toolbox are shown in the below figure:
  • These are a lot of controls and we will cover most of them in our coming tutorials but rite now we are just interested in knowing How to add these C# Controls in Windows Form we created in our previous tutorial.
  • So, the first C# Control I am gonna use is the Text Box, which is present in the Common Controls category.
  • So, what you need to do is to drag this Text Box from toolbox to your Windows Form and then it will be placed on your Windows Form as shown in below figure:
  • Now you can see in the above figure that our Form has a new C# Control in it which is a Text Box.
  • Now when you select this Text Box then its Properties will open up in the Properties Section.
  • From its Properties you can change many of its attributes.
  • The two main attributes in Properties of any C# Controls are Name and Text.
  • Name is the name of that Control with which we call it when we writing the code for that control.
  • Text is the text which appears on that Control for user to view.
  • Let me add another C# control on this Windows Form i.e. Button and then show you the difference between this Text and Name Property.
  • So, drag a Button from the Toolbox and place it on this Windows Form as shown in below Figure:
  • So, now we have two C# Controls on our Windows Form.
  • Now I will select the Button and then its Properties will open up in the Properties Section and I am gonna change its Text to Click Here as shown in below figure:
  • Now, lets see in the Form, what's written on the Button. :P
  • Wow the magic happened :D and what we have written in the Text Section of the Properties of this Button has appeared on it.
  • So, that's How the Text Property works. Whatever you written in the Text Section is appeared on that C# Control.
  • The Name of Button Control is still button1 so whenever I am gonna call this button in the back end code I will use that Name.
  • We are gonna do this in the next tutorial.
So, that's all for today. I hope you guys now have the idea How to add C# Controls in the Windows Form. In the coming tutorial, I am gonna add code behind each of these controls and will let you know How to use them. So, till then take care and have fun !!! :)

Introduction to C# Windows Forms

Hello everyone, hope you all are fien and having fun with your lives. Today, I am going to post a new C# tutorial in which we will have a Introduction to C# Windows Forms. Till now, we have seen Introduction to C# in which we have designed a console application in C# and after that we have discussed that project and write some code in it in First Code in C# Tutorial. So, till now we have an idea How to create a console application and how to run it easily.

I will continue with this C# console projects but first we have to discuss a little about C# Windows Forms. Microsoft Visual Studio is a very vast software so we can design different types of projects in it and also can use different languages. So, when talking about C#, we not only can design console applications but can also design C# Windows Forms in it. C# Windows Forms projects are much more easier than Console applications because in them you have a clear GUI in which you can drag and drop your components and can write the background code quite easily. So, let's get started with C# Windows Forms.

Introduction to C# Windows Forms

  • First of all create a new project in Microsoft Visual Studio and in the settings select C# Windows Forms as shown in below figure:
  • So, you can see in the above figure that all the steps are same as we did for creating a Console Application in Introduction to C# tutorial.
  • But the only difference here is that instead of selecting Console application, we are selecting Windows forms Applications.
  • Now, when you click OK then a new Project will open up as shown in below figure:
  • So, now our project is ready and we can design any kind of project on it, but first let's discuss its features.
  • If you have a look at it then you can see that it has three parts.
  • The center part is where we have our Form1, we will change its name later.
  • The on the left side we have a Toolbox which has all the components which can be used in this C# Windows Forms.
  • On the right side, we have this Solution Explorer and below it we have Properties panel.
  • So, let's discuss each of them separately.
Toolbox in C# Windows Forms
  • Here's an image of all the components in the toolbox of C# Windows Forms:
  • First of all there are categories like Common Controls etc and each of these categories has components in it which I have shown in detail by expanding these categories.
  • So, these all controls can be used in C# Windows Forms and it depends on your application, which one you want to use.
  • Most commonly used are buttons and text boxes etc which are in Common Controls section.
Solution Explorer in C# Windows Forms
  • Here's an image of the Solution Explorer in C# Windows forms:
  • This Solution Explorer shows all the files used in your C# Windows Forms Project.
  • First of all, we have the Properties folder which has the AssemblyInfo.cs file, it contains the basics things about your project like name and copyrights etc.
  • Then we have the References section, which has all the system library files.
  • Next we have the Form1.Designer.cs file which contains out Form1 design.
  • Finally we have the Program.cs file which has the back end code for our Form1.
  • All the code we are gonna write for our C# Windows forms Project is gonna be add in this Program.cs file.
Properties in C# Windows Forms
  • Here's an image of the Properties panel in C# Windows Forms:
  • Now when you select any component on your C# Windows Forms then its properties open up.
  • Rite now, I have selected the Main Form and its properties are appearing here.
  • Now from these properties you can change many attributes of your project.
  • Like for Form1, it says the name is Form1, so let me change the Text of it to something else as shown in below figure:
  • Now you can see in the above figure that I have changed the Text of this Form1 to Introduction to C# Windows Forms.
  • So, it will change the text of your Form to that as shown in below figure:
  • Now you can see the Name of our Form has changed to the text which we have written in the Text section of its properties.

So, that's all about the Introduction to C# Windows form. In the coming tutorials, we are gonna add controls from the toolbox in this C# and then we will add some back end code to make them work. So, till then take care and have fun !!! :)

First Project in C#

Hello everyone, I hope you all are fine and having fun with your lives. Today, we are going to design our First Project in C#. In the previous tutorial, we have seen a detailed Introduction to C#, where we have studied its importance in the software world.

Today, we are going to create our first project in C#. So, let's get started with our first code in the C# Tutorial series.

First Project in C#

  • I am going to use Microsoft Visual Studio 2019 Community Edition, which is free to use, and you can download it from its official website.
  • There are different languages available in Visual Studio i.e. C, C++, C# and F#. C# is the most commonly used programming language among all.
  • Now, I assume that you have installed Visual Studio and are ready to design your first project.
  • So, open your Microsoft Visual Studio, and create a New Project by clicking File and then New Project, as shown in the figure on the right.
  • You can also create a new project by clicking Ctrl+N.
  • Now once you create the New Project, a new pop up window will open up, as shown in below figure:
  • Now, as shown in the above figure, first of all, select the Visual C# as obviously we are gonna use the C# language in introduction to C#.
  • Next, select the Windows and then Console Application.
  • Next, we need to give a name to this Console Application, which I have given is MyFirstProject and finally click the OK button.
  • Now in this window, we are gonna update our code in C#. Currently, it has simple Hello World code, as shown in below figure:
  • Let's understand this code, line by line:

Namespace Declaration

  • The first line of code is "using System", here the System is a built-in C# Namespace and we are declaring it at the top of our code.
  • Currently, we are using just 1 namespace but later on, we are going to add a lot more and all these namespace declarations will come at the top of our code.
  • You can think of a namespace as a library that has different classes & methods in it.
  • So, when we declare it at the top, then all its classes become available to use in our code i.e. Console is a class of System namespace.

Projects Namespace

  • Next, we have namespace TEPProject, which is the namespace of our newly created project, all of our classes will be placed inside this namespace.
  • You can see this namespace has curly brackets { }, which has all the remaining code in them.

Program class

  • When you run your code, the compiler finds the project's namespace and inside this namespace, it makes a search for a C# Class named Program and in Program class, it goes into the C# Method named Main.
  • That's why we have the class Program inside our namespace TEPProject and inside this class, we have our static void Main(string[] args) function.
  • This Main function is a static function and it has arguments with datatype string.
  • This Main Function is the entry point of our compiler in our project, we have to write our code in this function or method. ( Functions are also called methods )
  • Inside this Main function, we have simply printed Hello World to our Console.
  • This Console is a member of namespace Systems, if we remove the namespace from the top then this Console will create the error.
So, now let's run our code and if everything goes fine then you will get something as shown in the below figure:
  • We have Hello World printed in our console panel, it's doing nothing else.
  • Moreover, if you are not getting things like C# Namespace or C# Methods etc. then no need to worry, we will cover all of them in coming tutorials in detail.

Extend C# Hello World Project

  • Solution Explorer contains all files of your project and Program.cs is the actual code file in which I am going to write our code.
  • So, let's add the below code in our Main function of Program.cs File:
Console.WriteLine("What are you learning ???");
string subject = Console.ReadLine();
Console.WriteLine("I am learning {0}", subject);
  • Now your Program.cs file will look something as shown in the below figure:
  • In the first line of code, I am printing "What are you learning ???" on the console.
  • In the second line, I am waiting for incoming data from the console, which the user has to enter, and I am saving that data in a string variable called subject.
  • In the third line, I am printing the data entered by the user on the Console.
  • You must have noticed {0}, it's one way of adding data in a string and is called Place Holder Syntax.
  • You can add as much data as you want, separated by commas, and can print them as {0} {1} {2} and so on.
  • Let's run our code and we will get a similar output, as shown in the below figure:
  • I have entered C# and it has printed it back, as you can see in the console.
  • Now when you press any key, the console will stop.
  • You can also use Concatenation instead of Place Holder Syntax, let's have a look at the third line, in below code:
  • So, now I have used + sign instead of curly brackets {0}, it's called concatenating a string.
  • If you run your code, you will get the same output, as shown in the above figure.
That's all for today. I hope you guys have got something out of it. In the next C# tutorial, we will have a look at Introduction to Data Types in C#. So stay tuned and have fun !!! :)

Introduction to C# ( C Sharp )

Hello friends, I hope you all are fine and having fun. Today, I am going to start a new series on C# Programming Language and today we are gonna have a look at first tutorial Introduction to C#.

Are you planning to study C# programming language? If so, then you have come to the right place. Knowing how to develop computer software is perhaps the most crucial ability to master in the present era. Computers have now made their way into practically every business. Whether it's an airplane's automation or a motorcycle's speedometer, computer programming languages are everywhere around us. And out of all the computer programming languages out there, C# is the most preferred and ideal language to learn. But why? Do not worry. This article contains all the answers to your questions. So, keep reading!

C# is the most widely used programming language for designing software & websites. Most of the software, we use in our daily life are designed using this C# Language. So, let's get started with a detailed Introduction to C#.

Introduction to C#

  • C# (pronounced see sharp) is a general-purpose programming language developed by Microsoft in 2000, as part of .NET framework.
  • Microsoft Visual Studio is a Programming environment used for writing C#.
  • C# was originally designed by Anders Hejlsberg, who currently works as the lead architect of C#.

C# Programming: The Language of God

C#, also known as the Language of God, is a contemporary, broad coding language that can help accomplish hundreds of activities and purposes in different fields. Microsoft designed C# and thus is typically used with the Windows .NET platform. The .NET Framework is actually a computer-developing framework that allows you to create applications for Windows, Azure, Web, and other programming platforms with programming languages including C#, Visual Basic, and F#. C# can also be used in an open standard system. The latest iteration of C# is version 7.2 and is specifically for Standard Language Framework. It has a syntax that is identical to Java. So, if you are familiar with Java or C++, it would be a piece of cake for you. Do not worry if you are a beginner. This article is specifically for beginners so they can have a better understanding before actually studying the language.

History of C#

Unlike well-established languages like Java, Python, PHP, and others, C# is a modern entry to the computer programming community over twenty-one years ago. Microsoft's Anders Hejlsberg, a Denmark computer programmer with a record of renowned innovations, created this programming language in 2000. The programming language was released in 2002 and has benefited all of us till today.

Why Should You Learn C#?

Now, most people have this question: Why Should I Learn C# and Not Others? Well, C# is a one-of-a-kind programming language that's also user-friendly and quicker to comprehend. It has excellent functionality in the areas of efficiency and requires relatively minimal resources. C# may be used to develop a wide range of applications. Some of these are listed below:
  • Windows consumer services by utilizing WPF, Windows Forms, and UWP
  • Network applications
  • Azure and Cloud applications
  • Modules, features, and terminal applications
  • Internet projects with ASP.NET Core and ASP.NET
  • Compatibility, information, and connectivity technologies
  • Android and iOS and Android phone applications by utilizing Xamarin
Other than developing applications, it is vital to learn C# because of three main reasons discussed below:
  1. High Salaries

In today's world, everyone wants to make a fair living, and computer programmers are among the most fortunate people out there. During the pandemic, almost everyone was having a hard time except the computer programmers because they continued their programming. With other programming languages, you get good salary packages. However, if you know the C# programming language, you will get job opportunities in multinational companies. You can also work online because it is highly demanded nowadays.
  1. C#: An Object-oriented Language

The second reason to study C# is that it is an object-intended programming language. Now, you might be thinking: what "object-intended" feature has to do anything with why you should learn C#? Well, object-intended indicates that it organizes data using objects and categories. This programming approach helps to minimize repeated coding and better regulates the data format. And all these factors help beginners to work efficiently and comfortably.
  1. Developed By Microsoft 

As discussed earlier, Microsoft created the C# programming language. It is a great reason why you should study C#. It means that there will be a plethora of excellent developer resources available to assist you in learning C# and no scarcity of its resources. And since Microsoft utilizes C# extensively, there is almost no chance that it will become obsolete in the coming years. So, mastering C# is, therefore, a long-term benefit. So, you see, these are solid reasons as to why you must learn C#. Now, we understand that you want to learn even more about C#, and we got you there. The upcoming section is a more in-depth detail of C# so, start taking notes!

Features of C#

Now, let us discuss the main features of the C# programming language in this section which are:
  1. Basic Features

  • In the C# programming language, pointers are not available.
  • It takes the characteristics of automated memory handling and garbage pickup from the .NET framework.
  • The "::" and "->" operators are not used in C#.
  • Direct memory modification and other risky activities are not permitted.
  • "==" is utilized for the comparative procedure, and "=" is for task execution.
  • Various ranges of fundamental kinds like Integers, Floats, and so on are available.
  1. Modern Features

  • C# follows the modern approach and is incredibly strong and convenient for creating interoperability and secure systems.
  • Any element conversion into an online service that is accessible via the internet is provided in C#.
  1. Type-Safe Features

  • Dangerous conversions are not possible in the C# programming language.
  • It is possible to check for an overflow of classes, and bound checking can be done.
  • The translator immediately initializes numeric forms (objects and instances) to zeros or reference kinds to blank.
  1. Object-oriented Features

  • Data abstraction, inheritance, flexibility, and interfaces are all supported in C#.
  • In Java language, basic kinds (float, int, double) are not things. However, C# has established structures that allow basic kinds to convert into objects.
  1. Upgradeable and Scalable Features

  • .NET has launched compositions that are self-defining in the areas of declaration. The manifest defines the assembly's identification, iteration, style, and electronic signature, among other characteristics.
  • Upgrading software elements is a time-consuming and error-prone process. But, C# supports versioning within the language, which might affect the current programming languages. Sophisticated frameworks can also be established and changed over time.
  • We erase old data and replace them with fresh ones to expand our system. Thanks to C#, there is no need to enroll in a flexible linking library.
  1. Interoperability Features

  • C# comes with built-in functionality for COM as well as Windows programs.
  • C# lets clients modify outdated codes by using pointers as harmful code blocks.
  • It enables local pointers to be used in a limited sense.
  • With C#, Customers no longer need to construct the unidentified or other COM interfaces because these characteristics are already included.
  • C# uses elements from Visual Basic for Applications (VB.NET) and other organized code technologies.

C# and C: What is the difference?

When studying the C# programming language, it is crucial to know the difference between C and C#. Both are coding languages, and that is why people often mess up between these two. But, do not worry. We will not let our readers go through the same mistake. Here is the difference: C is an overall-purpose coding language that includes features like recurrence, organized programming, semantic variable access, and many others. It is suitable for use in both system and integrated device programs. C is a limited modeling language whereas, C# is an object-intended programming language that includes features: garbage management, extensibility, type security, and uncomplicated class declarations. It may be used to create smartphones, desktops, and web applications. C# is a high-level programming language with a lot of complexity. So, both programming languages have the same initials but, they are complete opposites of each other.

How C# Programing language works

There is a dedicated set of libraries that are required to run C# in a machine. This collection of libraries is called the .NET framework and it has a collection of libraries that are called CLR’s (common language runtime). The .NET library belongs to Microsoft who has written the library on top of common language infrastructure that is commonly known as CLI which is an internationally acclaimed standard because of the way it assists seamless development and easy usage. When we write code in C#, it takes the form of IL (intermediate language) that is workable according to CLI specifications. These files then take the .dll extension after they are built. An assembly contains multiple dll files.

Basic Commands of C#

The basic commands of C# are quite similar to most popular languages such as C, C++ and Java. Moreover, C# is an object-oriented language so it has similar structures to the languages mentioned above. Some of the basic commands are listed below.

1. Using

The word “Using” is used to include libraries and API’s into your C# code. It is similar to the famous #include statement used in other languages. Any libraries written after the keyword Using will then be downloaded/included at runtime. It is also possible to have multiple Using statements in C#.

2. Class

The keyword class is used to define classes in C#. The syntax is as follows: Class User{ …. }

3. Comments

Comments are a common feature of any programming language. Developers usually add commented code in their files for the understanding of other people or as a reminder to themselves if they ever revisit their own code and want to understand how things work. Commented code is not compiled on run time. The compiler simply ignores any code written after/on a single line or any code written between a /* and a */.

4. Member or Class Variable

Instances are a common occurrence in programming languages. In C# the equivalent term is member or class variable. These are variables that are usually declared and defined when the classes are declared and defined.

5. Identifier

Identifiers are used to declare classes, variables, methods and members in C#. it helps keep track of specific classes and variables that have been defined by the user. Identifiers have simple rules that are to be followed. The rules for C# are similar to the rules for other languages. Also, it is important to note that Identifier can never be a variable name in C#.

Components of C#

Component classes are traditional classes that were used in C and C++ and also made their way to modern C#. These classes are used mainly for the purpose of containment as well as cleanup. Components are present inside a container and can do various operations on the container they belong to. A lot of the business processing is done in these components.

Disadvantages of C#

We have discussed many advantages of the C# programming language in the above sections. Now it is time that you learn about some of the disadvantages of the C#. Please keep in mind that the advantages of C# outweighs its disadvantages. Some of the disadvantages are listed below:
  • C# is a substandard x-platform GUI.
  • Because C# is a component of the.NET platform, the program must be executed only on a Windows operating system.
  • Because it is heavily reliant on the .Net platform, C# is much less versatile.
  • C# provides less versatility than C++.
  • Error correction demands a high level of expertise and understanding.

Conclusion

We hope that this article helped you in having a better understanding of the C# programming language. C# is an all-in-one programming language, and it has a bright future ahead of it. So, you should definitely give it a go because it is a long-term advantage. We wish you the best of luck on your journey! In the next tutorial, we will design our First Project in C#. Till then take care and have fun !!! :)
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir