C# Programming Beginner Tutorial: Basic Concepts and Ideas
Hello to all of my fellow Steemians! I decided to start sharing another one of my passions: Computer Programming! It can be quite rewarding to see an idea come to fruition and to be able to code it all in place yourself.
To start this excursion into my own personal Learning Annex and Mentorship Program, I am going to tell you a bit about the language that I use and what some of the basic things mean. I'll try to keep it to a minimal of jargon to start with here, so that everyone can be introduced... then, if you'd like to start learning the finer details, follow me and my posts.
C# is an Object Oriented Programming (OOP) language. In the simplest terms, this basically means that all the diffierent components for coding in C# are based on what they call objects. These objects can be lumped together, reused & extended as needed in order to generate the desired results.
An Object is any code that represents something. You could have an object that represents a vehicle or a screen or a game character or a whole bunch of different things. _Object_s are set up normally using 2 forms: structures and classes. Both of these options have their own rules and limitations. Struct (structure) objects hold basic object information to describe what it is. As an example, a vehicle should have some items (color, number of wheels, number of seats, etc.) that are common to all vehicles. Struct components can be extended to other objects, so there is a heirarchy that can be inherited (eg. the vehicle might need a description of a seat) from other objects. A struct can be used to create something, but in perspective a class is a struct (structure) that also allows for actions (methods/functions) to do things.
Programming is very much like Algebra: you create small formulas to get a result. Programming and Algebra both have Functions: sets of formulas that are set up to perform tasks to return results. Following you can see an example of this:
f(x) = x+1 would be algebra that allows you to replace x with a value, whether it's a number or another formula... public int f(int x) { return x+1; } would be the equivalent function in C#. The biggest difference is that, in C#, you need to decide how visible the function is to the rest of the code: public, protected, internal or private (I only really use public and private, personally). Then, I have to determine what kind of datatype will be sent back as the return data: int (the code keyword right after public). After that, the curly braces encompass the actual work of the function and describes each sequential action. In this example, we use the return keyword (which is required with most functions) to tell the program that we are taking the value of x and adding 1 to its value; and that value will be sent back.
*Note: x in Programming, as in Math, is called a variable.
C# is also an Event-Driven Programming Language. What this means is that each application that is developed using the C# language is based on User Events that trigger methods. These methods, then, would tell the computer the tasks to accomplish in a sequential fashion. The oldest of languages are based on sequential systems where the first line executes (performs its action) and then the next and the next in order unless a forced movement happens (the program might work to move the sequence to a specific line of code).
Events are, in essence, triggers that are embedded behind-the-scenes by the language itself. There are many different events that are available based on certain criteria (input device, keystrokes, interactions, etc.): mouse click, mouse hover, mouse move, key up, key down, leave a field, enter a field, and many more. If you were to look behind-the-scenes you would see code that works to do some of the following:
Create a component (item/pre-made object): buttons, labels, text fields, etc.
Design the look-and-feel of said component: color, font, size, x/y-coordinates, etc. (many of these are auto-generated if you use a visual interface for your programming needs).
Attach events to the component: mouse move, enter a field, etc.
Name the Method/Function attached to the Event... there are generic ways that are done automatically through the Interface.
Attach the component to other components to comprise a full design layout (eg. a button component on top of a form component).
Programming in a nutshell:
To make your computer do different things in sequence or based on events or interactions between components in order to accomplish specific tasks in a specific order. Creating an application that is able to accomplish specific tasks is a great accomplishment and can make you feel very good about yourself, but it can be very difficult to ensure thoroughness in your code. You must learn to understand just how much nuance is involved in coding as well as the level of detail that is involved. In addition, you must learn to follow the "breadcrumb trails" when the code doesn't work as intended in order to resolve issues, make on-the-fly modifications, revise the work-flow-process of the code, and adjust for different outcomes.
Another thing you, as a programmer, will need to consider is re-usability and extensibiity in your methods. As an example, if I wanted to pop up a form that allows the user to enter their first, middle, and last name and contact information (as a Contact Card or similar), you could code it within a specific application wherever you need to do so; however, it would be redundant, leave you open to issues if you don't copy the functional code exactly and do the exact same sequence. This is truly where Functions come into play, as they allow you to create a single set of instructions, give it a name, add in options to send information in/return information out, and use it from anywhere within the code. Following is an example (pay no attention to the actual syntax as you may not understand much of it):
public int LengthOfName(string name_in)
{
return name_in.Length;
}
What the above says is like this:
We are making a function that is public, accessible by the entire program.
We are going to return an int (integer) datatype.
We are giving the function a name called "LengthOfName".
We are allowing a string datatype to be sent in.
We are giving the string datatype a name called "name_in".
We are giving this a set of instructions.
We are going to return a value, based on the "name_in" variable and the "Length" extension.
*Note: Do not worry if you don't understand all of the terms yet, I wil delve into them further in subsequent posts.
Now that you have that "LengthOfName" function, what can you do with it? You can use it anywhere in your code by "calling" it. This means that you can have a shortened statement that tells the computer to jump over to that function in order to execute the instructions within it, then to come back and continue on. You will see how this is handled below:
.
.
.
LengthOfName("Boris Karlov");
.
.
.
What you see there is that you can use "LengthOfName(...)" like the "f(x)" Math Function notation to jump to the "LengthOfName" function with a string datatype parameter of "Boris Karlov". Once in that function, it will then return the "Length" extension (this is a framework-based attribute that does not need to be defined) of the string "Boris Karlov": an integer (int datatype to return) of 12.
I'm hoping that, so far, this makes sense. If so, then you're in a good place. Now it's time for Homework!!!
Pseudocode
Pseudocode is basically a way to code without code. In many of these cases, you are actually giving your brain a way to explain how to do a mundane task step-by-step in order to figure out how much nuance and detail is involved. As my example (the "//" is a comment tag that tells the program to ignore what's behind it):
MakeAPeanutButterAndJellySandwich() //no parameters sent in, as indicated by the empty ()
{
Stand up(); //this might encompass all the small movements to stand
Walk to the fridge.
Open fridge doors.
Pull out bread from 2nd shelf.
Move taco dip and ketchup on top shelf.
Pull out jelly from top shelf.
Walk to cupboard.
Open cupboard door.
Pull out PB from bottom shelf.
Carry items to table.
Place items on table.
Open bread bag.
Pull out 2 slices of bread.
Tie up bread bag.
Twist off PB lid.
Pick up knife.
Pick up PB on knife.
Spread PB on 1 slice of bread with knife.
Wipe knife blade on PB jar opening.
Put knife on napkin.
Twist lid back onto PB jar.
Pick up jelly bottle.
Flip open jelly lid.
Squirt jelly onto 2nd sice of bread.
Flip jelly lid closed.
Put Jelly bottle on tabletop.
Squish 2 slices of bread together.
Smear jelly against PB until spread wide.
Pick up PB jar.
Pick up bread.
Pick up Jelly.
Walk to cupboard.
Put PB jar in cupboard.
Put Jelly in fridge.
Put bread in fridge.
Walk to table.
Sit down in chair.
Stare at handiwork.
}
YOUR HOMEWORK
In the comments below, I would like to see 2 things:
- To know what steps I missed in the Pseudocode. I intentionally left out a few steps and I'm sure I could be even more detailed. List out some of the steps I missed.
- Your own Pseudocode for a set instructions to perform a task. Be creative, be funny, but be complete. I want to see how many of you out there can do this.
This is the end of your beginner tutorial. I hope you enjoyed it and feel a little more confident that you can learn to program, because if you keep your eyes peeled (follow me, upvote this post, and resteem it) you should see more of these tutorials and explanations in the coming weeks.
Let me know what you think.
Thanks.
Upvoted on behalf of the dropAhead Curation Team!
Your post will be Resteemed by @dropahead witness account of the dropAhead curation team!
Watch out for the #xx-votesplus tag!
By doing the above you will give us more STEEM POWER (SP) to give YOU more earnings next time.
Keep up the good work!
Celebrate with us "150+ days of the dropAhead curation team!"
Most recent post: ¡Castellano!
Good post. I am not really a beginner so I probably shouldn't comment, but I am going to chip you on your syntax. Good code reads just the same as good pseudocode to me, so to emphasis the OO of your example you could have had :-
WalkTo(fridge);
Open(fridge);
But anyway, you left the fridge and cupboard doors open :)
LOL, you guys are funny
I actually had something in that order, but I decided it might confuse new learners a bit too much. I was truly going for just the steps involved in a process. Nice catch on the doors.
Thanks for the feedback.
@dbzfan4awhile,
This gem of a post was discovered by the @OCD Curator team!
Please Reply to this comment if you accept, and are willing to let us share your gem of a post! By accepting this, you have a chance to receive extra rewards and one of your photos in this article may be used on our compilation post!
You can follow @ocd – learn more about the project and see other Gems! We strive for transparency!
Cool and interesting post jj, thanks for sharing with us! I wish i knew more about programming.
Well Ma1ne, my friend, keep a watch out and read the tutorials that I post and perhaps you'll start to catch on and excel! Btw, I accept this nomination! Thanks so much!
Congratulations @dbzfan4awhile! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
not an "easier" language to learn. i've been trying to get into coding. my friends suggest front end javascript first as a beginning roadmap. I have limited experience, but I told him " I want to learn python first because it looks simple." He told me not to go for back end because of it's expertise level.
Thank you for the tips.
I'm looking forward to your future posts. Hoping for the best.
I learned C++ for my first language. I am thinking you would consider that back-end. I feel it doesn't matter where you start. Some people just don't see coding the way others do. For me, it is like a puzzle with pieces that fit together.
I moved from C++ to Java and it was really easy to switch over. Syntax is very similar. Can't say I have done much front end work to compare though.
hey bro, thanks for you're input. You are right, everyone does have a different learning style that can work for them.
I have been receiving mentorship from a friend and all of ya'll here.
I can understand that. I chose to explain C# because it's what I do for a living, so it's in my wheelhouse. Not an expert by any means, but I think with 5 years physical coding experience at a workplace gives me some level of expertise, at least as it pertains to the systems that I connect to.
I like dotNet because, as you code, you can enter the variable and then just hit the period key and (depending on the IDE of choice and settings) see a listing of the extension method options that are available. I think C# is a nice entry because of the straightforward nature (it's much like dotNet BASIC as well).
On a side-note, I'm looking at next year to start learning Python and Ruby on Rails (Ruby is used in-house and Python is supposedly simple and powerful).
I appreciate the feedback and look forward to talking to you further!
Thanks.
Intellisense is a feature of many development environments these days. I remember seeing it in Eclipse Java IDE and I think last time I wrote some JQuery it was even there too. My memory is a bit hazy and it's been a while tho.
So with Intellisense on those non-dotNet-style languages, is it basically predictive type suggestions then? I have limited experience with Java in any form and haven't looked at it seriously in a couple years.
It's not really predictive in any kind of intelligent way. Intellisense gives you a drop list of options and you can do an auto-complete based on the letters typed.
The list narrows the more letters you type.
Yeah that’s what I was describing as a predictive type suggestion... not really predictive so much as just filtering to the next alphabetic option. I use this in the combo box lists and such that I use.
I’m just not sure with Java what triggers the Intellisense (dotNet it is the period or just straight typing).
nicely written
I appreciate that, I try to write it so that a wide cross-section of people will be able to (at the least) follow along.
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by dbzfan4awhile from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews/crimsonclad, and netuoso. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.