Learn C# in One Day

Mini Bytes: You would be surprised, how i am going to teach C# language in one day. But it is possible, you can learn C# in one day, only if you know the basic of C/C++ language. If you don’t know basic of C/C++ then it would be difficult for you to learn C# language.

C# is a object oriented programming language. It was developed by Microsoft which is mostly based on C and C++ programming language.

In order to learn C# in one day, you need to do some required software’s for compiling the programs. You can download visual studio 2017 community edition and install it in your computer. This software was developed by Microsoft and it was free to use for education purpose.

Note: In this article i am not going to use any of the technical words which was used in C#. I going to use only normal keywords which you can understand so that you can learn C# in one day. Some of the keywords may seem technical but trust me those are program keywords.

Lets see some advantages of C# languages.

  1. Automatic garbage collections.
  2. Standard library.
  3. Assembly versioning.
  4. Events and properties.
  5. Indexers.
  6. Linq and Lambda expressions.
  7. Windows integration.
  8. Easy generics.
  9. Multi-threading.
  10. Events and delegates management.

Lets go to the topic. Below are the topics which i am going to discuss with examples.

  1. Syntax.
  2. Comments.
  3. Data Types.
  4. Variables.
  5. Type Conversions.
  6. Constants.
  7. Operators.
  8. Loops.
  9. Switch.
  10. Arrays.
  11. Namespace.
  12. Methods.
  13. String Manipulation.
  14. Class.
  15. Struct.
  16. Enums.
  17. Inheritance.
  18. Polymorphism.
  19. Overloading operator.
  20. Interface
  21. Try.
  22. Catch.
  23. Multiple Catch.
  24. Final.
  25. File I/O.

C# – Syntax:

You can easily learn c# in one day, if you know the basic syntax of the C# language. Like the common object oriented languages, C# language has simple an common syntax which looks much like the C and C++ language.

Above code will open a command prompt and displays “Hello World”. Class was declared as public so you can access any of the methods created inside throughout the program.

C# – Comments:

  1.  // -> one line comment.
  2. /* Your comments here*/ -> Multiple line comments.
Tip: /// -> This syntax can be used to trigger a comment summary in your Visual Studio 2017.

C# – Data Types:

Data types can be categorized into 3 types.

  1. Value types
  2. Pointer types
  3. Reference types

Please refer the data types in detail to learn C# data types.

Values Types:

Below are the value data types you can use in your C# program.

TypeRepresentsRangeDefault Value
boolBoolean valueTrue or FalseFalse
byte8-bit unsigned integer0 to 255
char16-bit Unicode characterU +0000 to U +ffff‘\0’
decimal128-bit precise decimal values with 28-29 significant digits(-7.9 x 1028 to 7.9 x 1028) / 100 to 280.0M
double64-bit double-precision floating point type(+/-)5.0 x 10-324 to (+/-)1.7 x 103080.0D
float32-bit single-precision floating point type-3.4 x 1038 to + 3.4 x 10380.0F
int32-bit signed integer type-2,147,483,648 to 2,147,483,647
long64-bit signed integer type-9,223,372,036,854,775,808 to 9,223,372,036,854,775,8070L
sbyte8-bit signed integer type-128 to 127
short16-bit signed integer type-32,768 to 32,767
uint32-bit unsigned integer type0 to 4,294,967,295
ulong64-bit unsigned integer type0 to 18,446,744,073,709,551,615
ushort16-bit unsigned integer type0 to 65,535

Pointer type:

You can use these type of variables to store the pointers. i.e. it was used to store the memory address of another data type.

E.g:

Reference type:

Reference type is used to store the references to their data objects. Below are some of the reference type examples.

The following keywords are used to declare reference types:

C# also provides the following built-in reference types:

C# – Variables:

Variables are nothing but a name that you assign to the storage location. Variables can be of different types such as integer, float, decimal, string etc…You need to assign a name which can be understandable by the coders.

variables

Syntax:

Eg:

Above are declared variables, but if you want to initialize a variable, then you need to assign values to the variable, like you fill the storage area with necessary content which you need to store.

C# – Type Conversions:

Type conversions are used to convert one data type to another data type. Thought you cant able to convert all the available data type to necessary data, below are some of the data type conversion methods you can use.

type_conversion

Sr.No.Methods & Description
1ToBoolean

Converts a type to a Boolean value, where possible.

2ToByte

Converts a type to a byte.

3ToChar

Converts a type to a single Unicode character, where possible.

4ToDateTime

Converts a type (integer or string type) to date-time structures.

5ToDecimal

Converts a floating point or integer type to a decimal type.

6ToDouble

Converts a type to a double type.

7ToInt16

Converts a type to a 16-bit integer.

8ToInt32

Converts a type to a 32-bit integer.

9ToInt64

Converts a type to a 64-bit integer.

10ToSbyte

Converts a type to a signed byte type.

11ToSingle

Converts a type to a small floating point number.

12ToString

Converts a type to a string.

13ToType

Converts a type to a specified type.

14ToUInt16

Converts a type to an unsigned int type.

15ToUInt32

Converts a type to an unsigned long type.

16ToUInt64

Converts a type to an unsigned big integer.

Eg:

Type conversions completely depend on the type of data which you are going to convert. There are certain methods available which do throw error if the type conversions doesn’t work much like we want.

C# – Constant:

If you assign a constant variable , then this variable cannot be modified at the time of execution.

Constant can be of any type like integer, floating or character. Below are some of the literals which we can use

Character constants should always be enclosed inside single quotes and it can be assigned to a variable.

Escape sequenceMeaning
\\\ character
\’‘ character
\”” character
\?? character
\aAlert or bell
\bBackspace
\fForm feed
\nNewline
\rCarriage return
\tHorizontal tab
\vVertical tab
\xhh . . .Hexadecimal number of one or more digits

Syntax:

Eg:

C# – Operator:

Operators are the symbols which was used by the compiler to do the arithmetic operations such as addition, multiplication, subtraction etc…There are 6 different kinds of operator.

  • Arithmetic Operators (+, -, *, ++, –, /, % etc…)
  • Relational Operators (=, !=, >=, <=, >, < etc…)
  • Logical Operators (&&, ||, !)
  • Bitwise Operators( &, |, ^ etc…)
  • Assignment Operators (=, += , -=, *=, !=, >>=, <<= etc…)
  • Misc Operators (sizeof(), typeof(), *,&,is,as etc…)

operators

Eg:

C# – Loops:

In C# loops are used to execute the code several times. I.e you can run the code whenever the condition is satisfied or not, or you can run the code for specific number of times. Different kinds of loops which are using in C# are as follows

loops

While Loop:

For Loop:

Do While Loop:

Nested Loops:

Eg:

C# – Switch:

Switch can be used to execute a list of statements that matches the expression. There are various usage for switch statement and it was one of my favorite in C#.

Eg:

C# – Array:

In C# Array is nothing but a sequential collection of data. In latest C# we are using list in most cases instead of array because of its simplicity and robust feature.

An array can be declared, initialized and cleared and than same can also be done in List. To learn C# in one day, then you need to know basic of arrays concept. Because while coding you will face challenges in handling arrays.

Syntax:

Eg:

An array can be accessed with the help of its sequence number which start from 0.

Eg:

C# – Namespace:

Namespace is used to keep the names separately to avoid avoid conflicts between different classes. Once a namespace is given to a class then specific class in C# can be called with the help of the namespace. It will not conflict with the other classes.

namespace

C# – Methods:

In C# Methods are called as a group of statements that produces output. This output can also be used by another method. This is the basic for learning C#, because if you want to learn any kind of language, then you need to know how to create and call methods. below is the syntax for the methods.

To learn C# in one day, then you need to know basic of how methods can be created.

In many cases method was also called as functions. Here access specifiers are

  1. public.
  2. private.
  3. protected.
  4. internal

method

Return type can be of any data type which you are going to return such as string, list, integer etc. You need to give a name for the method and you can also pass the parameters if you need. In order to learn C# in one day, you need to know how to create methods.

C# – Class:

Class consists of operations that need to be performed during execution. It will enclose declared variables, group of methods which can be used by another classes i.e like a library which contains all the available operations predefined. To learn C# in one day, then you need to know basic of how class can be created.

Below is the syntax for creating class.

Eg:

C# – String Manipulation:

Strings are one of the important part of the program. Without it you cant output a result and most of the results cannot be determined. So in-order to use strings in different ways, there are manipulation techniques available in C# such as string concatenation, finding sub-string, searching string, joining string, splitting string etc…

Eg:

Below are some escape sequence which you can use in the string manipulations.

Escape sequenceCharacter nameUnicode encoding
\’Single quote0x0027
\”Double quote0x0022
\\Backslash0x005C
\0Null0x0000
\aAlert0x0007
\bBackspace0x0008
\fForm feed0x000C
\nNew line0x000A
\rCarriage return0x000D
\tHorizontal tab0x0009
\UUnicode escape sequence for surrogate pairs.\Unnnnnnnn
\uUnicode escape sequence\u0041 = “A”
\vVertical tab0x000B
\xUnicode escape sequence similar to “\u” except with variable length.\x0041 = “A”

C# – Structs:

Struct is use to hold related value of various data types. It was used to hold small group of related data. Keyword used for struct is “Struct”. Below example shows how to declare struct in C#.

C# – Enum:

Enum is used to declare the named constants which is called as the enumerator list.

We can also use initializers in enum to override default values.

C# – Inheritance:

In C# Inheritance is an important concept. You can write C# code without inheritance but it will take more time to complete the code because without inheritance you need to create and declare the variables and methods again and again.

To learn C# in one day, then you need to know basic of inheritance concept.

Inheritance is used to create a base class that gives us specific functionality and in another class the base class functionality can be inherited ( like importing and using) or it can be overridden.

Below is a simple example which can be used to know more about inheritance.

C# – Polymorphism & Overloading Operator:

Polymorphism means having many shapes. It has two types

  1. Static Polymorphism.
  2. Dynamic Polymorphism.

Static Polymorphism:

Links a function with an object during run-time. It was differentiated into two different types.

Function Overloading:

Multiple functions having same function name is called function overloading.

Operator Overloading:

Redefining or overloading the builtin operator again and again is called operator overloading.

Dynamic Polymorphism:

It was used to create abstract class. Abstract class contains abstract methods.

C# – Interface:

Interface contains definitions and declarations for the class and struct. Interface may also contain related functions related to the class and struct.

interface

You can simple implement the interface which contains the predefined function declarations.

C# – Try & Catch:

Try Catch statement is used to execute the statements which was given inside the try block and throw the exception to the catch block. It was most widely used to debug the program. Each and every developers will use the try-catch statement and find out the error occurred while executing the statements.

To learn C# in one day, then you need to know basic of try-catch statement for debugging.

try_catch

Syntax:

Eg:

C# – Multiple Catch:

Multiple catch contains multiple catch block in the try-catch statement to catch manual or specific exceptions. But if you use “Exceptions” then it will catch all the exceptions which was thrown from try block.

C# – Final:

In try-catch block, the last block which we can use is final block. Whether or not whenever try-catch block runs, final block was always executed. This helps you to catch the database exceptions and dispose it in the final block even after throwing errors.

C# – File I/O:

It was called File Input and Output operations. In Windows whenever you are reading the files or writing the files, it was always done like a stream. So the input steam is used for reading the file and output stream is used for writing the file.

To learn C# in one day, then you need to know basic of handling file i/o operations.

There are different file stream classes which can be used to read and write files in different formats.

Sr.No.I/O Class & Description
1BinaryReader

Reads primitive data from a binary stream.

2BinaryWriter

Writes primitive data in binary format.

3BufferedStream

A temporary storage for a stream of bytes.

4Directory

Helps in manipulating a directory structure.

5DirectoryInfo

Used for performing operations on directories.

6DriveInfo

Provides information for the drives.

7File

Helps in manipulating files.

8FileInfo

Used for performing operations on files.

9FileStream

Used to read from and write to any location in a file.

10MemoryStream

Used for random access to streamed data stored in memory.

11Path

Performs operations on path information.

12StreamReader

Used for reading characters from a byte stream.

13StreamWriter

Is used for writing characters to a stream.

14StringReader

Is used for reading from a string buffer.

15StringWriter

Is used for writing into a string buffer.

Eg:

From the above contents, you can learn c# in one day if and only you know the concepts clearly. I have only specified basic details about the concepts which was used in C# language. If you want to learn more in details, then you need to approach professionals to get in-depth knowledge about C#. Here is is the link from Microsoft where can get documentation for C#

Above post was created base on the content from tutorialspoint

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

1 + 7 =