How to use IF Loop in C#
Hello everyone, I hope you all are doing great. Today, we are gonna have a look at IF Loops in C# and it's 8th tutorial in C# series. So far, we have discussed some basic concepts in C# and now we are ready to get our hands on Loops in C#.
C#, as any other programming language, supports a lot of loop structures, we will discuss each one of them separately in our coming tutorials. Today, we will discuss the simplest of them all, which is IF loop, so let's get started with How to use IF Loop in C#:
How to use IF Loop in C#
- IF Loop in C# takes a Boolean expression as a condition and if this condition is TRUE, the compiler executes the code inside IF loop { } and if the condition is wrong, the compiler simply ignores the code.
- Here's the syntax of IF Loop in C#:
if (boolean-expression)
{
// Code will come here, execute if the Condition is TRUE.
}
- Let's create a simple program, where we ask the user to enter his Physics marks and the program will tell the user whether he is passed or failed.
- I have used If loop and the condition I have used is, if the marks are less than 50 then student has failed & if its equal or greater than 50 then the user has passed.
- Here's the code for IF loop in C#, shown in below figure:
- You can see in above figure that I have entered 25, now when the compiler will come to first IF loop, it will check the condition (Marks >= 50), which is not true as the number we entered is less than 50, so the compiler will simply ignore this IF loop and will move on to second IF Loop.
- The condition in second IF Loop is (Marks < 50), and clearly this condition is TRUE, so our compiler will enter in this IF Loop, enclosed by curly brackets { }, and will print out "You failed the exam.".
- So, in simple words:
- IF condition is TRUE => Execute.
- IF condition is FALSE => Ignore.
- Few commonly used conditional operators of IF Loops are:
- Equal to ( == )
- Not Equal to ( != )
- Greater than ( > )
- Less than ( < )
- Greater than or Equal to ( >= )
- Less than or Equal to ( <= )
- We could also use multiple conditions in single IF Loop using these two operators:
- && ( AND ) => it returns TRUE, if both conditions are TRUE.
- || ( OR ) => it returns TRUE, if either of two conditions is TRUE.
- Let's edit out code a little and add a 3rd condition, as shown in below figure:
- Here, I have used three IF Loops in above code and have used && operator in second IF Loop.
- So, if the number is in between 50 & 90, then second loop will execute, both conditions have to be TRUE.
- I hope you have understood How to use IF Loop in C#, now let's move a little forward and have a look at IF Else Loop in C#, which is kind of an extension of IF Loop.
IF-Else Loop in C#
- Instead of using separate IF Loops for different conditions, we can use single IF-Else Loop.
- In our first code, we have used two IF Loops to check whether student has passed or failed.
- Let's rewrite that code using IF-Else Loop, as shown in below figure:
- As you can see in above figure, first I have used IF Loop and placed a condition that if (Marks >= 50) then print "you passed the exam" otherwise simply print "you failed the exam".
- Else condition is like the default option, if "IF" Loop failed to execute then "ELSE" will be executed and if "IF" loop is successful, then "ELSE" will be ignored.
- That was the case for two IF Loops, but what if we have more than two IF Loops, as in our second code, we have 3 IF Loops, let's rewrite that code using IF-Else Loop:
- The above code is working exactly the same as our code with 3 IF Loops but here we are using IF-Else Loop.
- In IF-Else Loop, the first loop will be "if" loop and the last one will be "else" loop while all the intermediary loops will be "else if" loops.
- Here's the final code for today's lecture:
using System;
namespace TEPProject
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter your Physics marks: ");
int Marks = int.Parse(Console.ReadLine());
if (Marks >= 90)
{
Console.WriteLine("You got A+ grade. \n\n");
}
else if (Marks >= 50 && Marks < 90)
{
Console.WriteLine("You passed the exam. \n\n");
}
else
{
Console.WriteLine("You failed the exam. \n\n");
}
}
}
}
So, that was all for today. I hope now you can easily use IF-Else Loop in C#, if you have any problems, ask in comments. In our next tutorial, we will have a look at How to use Switch statement in C#. Till then take care & have fun !!! :)
What is difference between PCB and PCBA
Hello friends, I hope you all are doing great. In today’s tutorial, we will have a look at
what is difference between PCB and PCBA. The printed circuit board (
PCB) is a circuitry board that used to construct engineering projects and electronic devices circuits. The invention of this board has reduced complicated wiring circuits that were used before its creation, the circuits manufactured by the complex wiring were very difficult to handle in sense of fault detection and reconstruction. The printed circuit board is manufactured by a substrate material that is constructed by material such as glass fibre, epoxy resins.
On this board, a large number of conductive paths are designed on which different symbols of electronic components are sketched so we can easily connect our components to make circuits. There are many
types of PCB that have their own structure designing and practical application. In today's post, we will have a detailed look at the printed circuit board and PCBA, compare them with detail description. So let's get started with
What is difference between PCB and PCBA.
What is difference between PCB and PCBA
What is a PCB?
- The printed circuit board is a circuitry board that used to creation of circuits. On this circuitry board, there are numerous layers of copper designed for circuits creation.
- The base material used for this circuit board is manufactured by the epoxy resin and glass fibre.
- This circuit board is available in one layer to many layers according to circuitry for which it used like double-sided PCB, multi-sided PCB.
- In simple circuits single-layer printed circuit board is used while in complicated circuits like the motherboard of a computer, GPS (global positioning system) double layer or multilayer PCB is used.
- In electronic devices like televisions, mobile phones, and other electronic devices used printed circuit board their circuitry construction.
- With the usage of technical instruments, it also used in medical instruments like CT (computed tomography) scan machine, X-Ray, etc.
PCBWay
- PCBWay is a famous printed circuit board producer company that offers different features and services related to PCB. Its main services are given here.
- It is located in china.
- It delivers an order to clients within a given time and uses DHL for delivering orders
- It provides prototypes fabrications within working twenty-four hours.
- Its management team consists of more fifty professionals technicians and engineers
- Its provided quality is satisfying the clients all over the world.
PCB Designing
- There is numerous option available in the manufacturing of printed circuit board every single board of PCB has its own designing and layout according to project requirements.
- The PCB manufacturers used computed aided designing techniques for assembly of a printed circuit board.
- With the using of different software, PCB producer should also have skills to provide the board according to circuit and customer designing requirements.
- After making a layout of the circuit a sample of that circuit is copied on a plastic paper sheet to make some corrections.
Types of PCB
Single-Sided PCB
- In this type of printed circuit board, the conductive layers are designed on one side of board and all circuits are manufactured on this PCB side.
Double-Sided PCB
- In this PCB both sides of the board are used for the construction of circuits and both sides have a conductive layer. Its main benefits are that both sides elements are connected with each other through holes that are already designed on it.
Multi-layered PCB
- In this type of printed circuit board, there are more than two-layers are manufactured that has their own conductive paths and circuits are manufactured on each layer according to user requirement.
Material used For PCB Manufacturing
- For the manufacturing of PCB, the base substance normally called substrate is manufactured with the fibreglass or epoxy resins.
- Some boards have substrate manufactured by the fibreglass and epoxy resin.
- Some manufacturers used rein-forced phenolic resin blended with the copper, PCB production by this process is less costly than other PCBs.
- Such a circuit board is normally used household devices and electric circuitry.
- Different layers of copper are designed on a substrate material, for protection of this board from outer environment layer tin and the lead mixture is coated.
What is PCBA?
- PCBA stands for printed circuit board assembly. It is a board that we have after complete circuit manufacturing and assembly of different elements.
- If we compare a simple printed circuit board with a printed circuit board assembly or PCBA, then we will find that the PCB is only circuit board while PCBA is circuit board having completer packaging and assembly of different components.
- The elements that are used to make circuitry in printed circuit board assembly are an inductor, capacitor, diodes resistances, etc.
Technique Used in PCBA
- There are 2 main methods used in printed circuit board assembly first one through-hole technology and the second one is surface-mounted. Let's discuss these two with detailed.
Surface-Mount Technology:
- This technique is the best option for small circuitry and elements used in circuits. This process uses 3 different steps for the assembly of PCBA.
- In the First step at the surface of the circuit board, solder paste is spread.
- After that, all components of the respective circuitry are assembled on their respective places.
- In the final step, the board is kept in an oven of five hundred degrees celsius to make solder paste soft so circuit components get assembled properly.
Through-Hole Technology
- In this technique there are three steps are followed like the surface-mounted technique. In first step elements of circuitry are manually assembled on the board.
- In the second step connections of all elements are checked either they are correct or not.
- After that PCBA is passed through a liquid solder at five hundred degrees Fahrenheit.
PCB vs PCBA
- Till now I hope you have learned detailed on PCB and PCBA now we discuss their main differences.
Manufacturing Procedure:
- The manufacturing od PCB is very simple than the PCBA. In printed circuit board assembly we use special techniques for circuits designing and used an oven for fine connections of components.
Cost:
- The price of PCB is less than the PCBA, in PCBA due to complex circuitry different expensive components are used.
Functionality
- The printed circuit board is just a simple board have no component for circuitry to get or provide supply.
- While in PCBA all necessary components are available for the proper working of the circuit.
Packaging
- The PCB is available in vacuum packaging and a printed circuit board is anti-static packaging.
That is the detailed article about PCB and PCBA, I have mentioned each and everything related to these two. If you still have any question ask in comments. Thanks for reading.
Reasons to Choose an Engineering Recruitment Agency
Hello friends, I hope you all are doing great. In today’s tutorial, we will have a look at Reasons to Choose an Engineering Recruitment Agency. Essentially, the recruitment process is meant to save time for the employer who is looking to hire, as well as for the person who is seeking a certain job. The whole process gets a lot easier and effective, making both the employer and future employees get their hands on the best deal possible.
However, both of the aforementioned parties may lack what it takes to make the hiring process more effective. After all, recruitment is not just finding a job for a random individual.
Recruiting implies matching someone with the skills, experience, and career expectations they have with the right job for them. This is one of the main reasons why you – either an employee or employer – should rely on engineering agency specialists like CBSbutler Recruitment, Nolan Recruitment etc. So let's get started with Reasons to Choose an Engineering Recruitment Agency.
Insider Knowledge of Roles and Companies
- There are hundreds of job boards, job search engines and recruiters posting jobs. For example, a common job advert will most likely tell you the location of your job, its salary, and a short description of your role and responsibilities.
- If you rely on a recruitment agency, like the one mentioned above, you can be given a lot more information about the engineering company and the role you want to be a part of.
- Moreover, such agencies can also give you information about other companies that are currently expanding and looking for employees.
Helping You More than Your CV
- For example, there are even specialist recruiters within the engineering sector, Navartis Civil Engineering Recruitment being one of those who can promote you over and above what is stated on your CV.
- While your CV comes in handy in terms of showcasing your experience or education, the piece of paper will never be able to sell your character and strengths.
- Naturally, a recruitment agency is able to do that and will certainly provide an interested company with more information about you than a simple CV and cover letter.
Interview Preparation
- While working with a recruitment agency, a consultant will be by your side for the whole duration of the recruitment process. Obviously, this implies interview preparation.
- On top of that, keep in mind that consultants are there to prepare you for the best interview of your life.
- You won’t have to worry about messing up, because the consultant has to make sure that you are fully prepared for the interview. After all, if you aren’t, then they will not get paid!
Getting the Best Deal
- Last but not least, a recruitment agency – via a consultant – is able to negotiate the best deal for you and your expectations. You will no longer have to face an employer and their unpleasant offer.
- Your consultant will show you the available offers and you’ll be able to either choose one or tell them your opinions – namely, that you don’t consider those offers as being a good deal for you.
The Bottom Line
- Most people say that recruiters and consultants are actually trying to take money away from them. However, the market doesn’t work like that. Nowadays, most recruitment agencies work with employers and only present you with available jobs.
- On the other hand, if you have to rely on an agency to find you a new job, then you can be sure that they’ll do their best! Why? This is because agents/consultants have a fixed percentage that they agree on upfront with you.
- Basically, this means that the better the deal you get in terms of a job, the better the agents get paid. It is in their best interest to get you the job of your dreams!
It is a complete tutorial on Reasons to Choose an Engineering Recruitment Agency if you have any questions about it ask in the comments. Thanks for reading.
How to use Arrays in C# ???
Hello friends, I hope you all are having fun. In today's tutorial, we are going to discuss
How to use Arrays in C#. It's our 6th tutorial in C# series and currently we are focusing on basic concepts in C#.
Without understanding these simple concepts, we can't move forward. So, let's get started with Arrays in C#:
How to use Arrays in C# ???
- An array (base type System.Array) is a collection of similar (like-typed) data types, called by a common name. Each data item is referred as an element of array and is assigned an index starting from 0.
- As C# array is an object so we can find its length using member length, which is actually a count of total number of data items in that array.
- Arrays are reference types and implement IEnumerable that's why, we have to use new keyword for new instance of array.
- Here's an example of an array in action:
- You can see in above code that I have first initialized an array named TEPArray and I have fixed its size to 3.
- After that, I have added values in the array at each index 0, 1 and 2. If we count we have 3 positions which is the size of our array.
- After that, I am simply printing those values in the console.
Why we need to use Arrays ???
- Let's say you are working on some project where you need to show marks of some students, let's say 50 students.
- In such cases, it would be too difficult to create separate variable for each student. Instead, you can simply create an array of each subject and save all students' marks in single variable.
- In simple words, we use arrays to handle big data of similar data types.
- Arrays are strongly typed i.e. they take data of single data type, we can't add multiple data types in single array.
- We can't increase Array size after initialization, as in above code I have initialized the array with fixed size of 3 so now if I add a 4th element, then compiler will generate an error. Although, we can use foreach iteration on all arrays in C#, we will discuss that later.
Different ways to initialize Arrays in C#
- There are three different ways to initialize arrays in C#, although they are all same at the end but slightly different in syntax.
- I have shown all these three ways in below figure:
- As you can see in above code, the first way is the same one, we first initialized the array and then added values in it.
- In the second way, we have initialized the array and added values in it, in a single line.
- In the third way, I have just declared the arrays and haven't added the size or the data in it.
- After that I have initialized them and then added values, arrays don't occupy any memory unless initialized.
- Here's the complete code, which we have designed so far:
using System;
namespace TEPProject
{
class Program
{
static void Main(string[] args)
{
// First Way: Initialization first & then added values
int[] TEPArray = new int[3];
TEPArray[0] = 1;
TEPArray[1] = 2;
TEPArray[2] = 3;
// Second Way: Initialization & values added in a single line
int[] TEPArray2 = new int[5] { 1, 2, 3, 4, 5 };
Console.WriteLine("Code Designed by www.TheEngineeringProjects.com \n");
Console.WriteLine("Value at Index 0 is : {0} \n", TEPArray[0]);
Console.WriteLine("Value at index 2 is : {0} \n", TEPArray[2]);
Console.WriteLine("Length of Second Array : {0} \n", TEPArray2.Length);
Console.WriteLine("First element of Second Array : {0} \n", TEPArray2[0]);
// Third Way: Declared First & then initialized & values added
string[] TEPArray3, TEPArray4;
TEPArray3 = new string[5] {"Hello","welcome","to","C#","Tutorial"};
TEPArray4 = new string[] { "Designed", "by", "The", "Engineering", "Projects" };
Console.WriteLine("\n\n");
Console.Write("For loop : ");
for (int i = 0; i < TEPArray3.Length; i++)
Console.Write(TEPArray3[i] + " ");
Console.WriteLine("\n\n");
Console.Write("For-each loop : ");
// using for-each loop
foreach (string i in TEPArray4)
Console.Write(" " + i);
Console.WriteLine("\n\n");
}
}
}
- Till now, we have discussed only One Dimensional Arrays, now let's have a look at Multi-Dimensional Arrays:
Multi-Dimensional Arrays in C#
- We have seen single row of data in arrays so far, but we can also add multiple rows in arrays and such arrays are called Multi-Dimensional Arrays or Rectangular Arrays.
- They are called rectangular because length of each row has to be same in a single array.
- Let's have a look at Multi-Dimensional Array in below figure:
- In the above code, you can see i have created two arrays, the first one TEPArray1 is a 2-Dimensional Array, while TEPArray2 is a 3-Dimensional Array.
- I have also used nested for loop to display data of 2D array, if you can't understand it yet, don't worry we will discuss it in detail in coming lectures.
- But make sure you understand, how I am accessing elements of multi-dimensional arrays.
- Here's the complete code for Multi-Dimensional Arrays in C#:
using System;
namespace TEPProject
{
class Program
{
static void Main(string[] args)
{
string[,] TEPArray1 = new string[4, 2] {
{ "one", "two" },
{ "three", "four" },
{ "five", "six" },
{ "seven", "eight" }
};
int[,,] TEPArray2 = new int[2, 2, 3] {
{
{ 1, 2, 3 },
{ 4, 5, 6 }
},
{
{ 7, 8, 9 },
{ 0, 1, 2 }
}
};
// Accessing array elements.
Console.WriteLine("Code Designed by www.TheEngineeringProjects.com \n");
Console.WriteLine("2DArray[0][0] : " + TEPArray1[0, 0]);
Console.WriteLine("2DArray[0][1] : " + TEPArray1[0, 1]);
Console.WriteLine("2DArray[1][1] : " + TEPArray1[1, 1]);
Console.WriteLine("2DArray[2][0] " + TEPArray1[2, 0]);
Console.WriteLine("\n\n");
Console.WriteLine("3DArray[1][0][1] : " + TEPArray2[1, 0, 1]);
Console.WriteLine("3DArray[1][1][2] : " + TEPArray2[1, 1, 2]);
Console.WriteLine("3DArray[0][1][1] : " + TEPArray2[0, 1, 1]);
Console.WriteLine("3DArray[1][0][2] : " + TEPArray2[1, 0, 2]);
Console.WriteLine("\n\n");
Console.WriteLine("For Loop:");
for (int i = 0; i < 4; i++)
for (int j = 0; j < 2; j++)
Console.Write(TEPArray1[i, j] + " ");
Console.WriteLine("\n\n");
}
}
}
So, that was all about Arrays in C#. If you got into any errors, then ask in comments. In next lecture, we will have a look at How to use Comments in C#. Till then take care & have fun !!! :)