Sunday, December 23, 2018

C# Enum (Enumeration)

C# Enumeration

An enumeration is used in any programming language to define a constant set of values. For example, the days of the week can be defined as an enumeration and used anywhere in the program. In C#, the enumeration is defined with the help of the keyword 'enum'.
Let's see an example of how we can use the 'enum' keyword.

In our example, we will define an enumeration called days, which will be used to store the days of the week. For each example, we will modify just the main function in our Program.cs file.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program 
 {
  enum Days{Sun,Mon,tue,Wed,thu,Fri,Sat};
  
  static void Main(string[] args) 
  {
   Console.Write(Days.Sun);
   
   Console.ReadKey();
  }
 }
}

Code Explanation:-

  1. The 'enum' data type is specified to declare an enumeration. The name of the enumeration is Days. All the days of the week are specified as values of the enumeration.
  2. Finally the console.write function is used to display one of the values of the enumeration.
If the above code is entered properly and the program is executed successfully, the following output will be displayed.


Output:












Sunday, December 2, 2018

C# Data Types with Example

1) Integer

An Integer data types are used to work with numbers. In this case, the numbers are whole numbers like 10, 20 or 30. In C#, the datatype is denoted by the Int32 keyword. Below is an example of how this datatype can be used. In our example, we will define an Int32 variable called num. We will then assign an Integer value to the variable and then display it accordingly


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
 { 
  static void Main(string[] args) 
  {
   Int32 num=30;
   Console.Write(num);  
   
   Console.ReadKey();
  }
 }
}
Code Explanation:- 

The Int32 data type is specified to declare an Integer variable called num. The variable is then assigned a value of 30. Finally the console.write function is used to display the number to the console. If the above code is entered properly and the program is executed successfully, following output will be displayed.



     From the output, you can clearly see that the Integer variable called num was displayed in the console

2) Double

A double data type is used to work with decimals. In this case, the numbers are whole numbers like 10.11, 20.22 or 30.33. In C#, the datatype is denoted by the keyword "Double". Below is an example of this datatype.In our example, we will define a double variable called num. We will then assign a Double value to the variable and then display it accordingly.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
 { 
  static void Main(string[] args) 
  {
   double num=30.33;
   Console.Write(num); 
   
   Console.ReadKey();
  }
 }
}

Code Explanation:-

  1. The double data type is specified to declare a double type variable called num. The variable is then assigned a value of 30.33.
  2. Finally the console.write function is used to display the number to the console.
If the above code is entered properly and the program is executed successfully, following output will be displayed.

Output:


From the output, you can clearly see that the double variable called num was displayed in the console

3) Boolean

A boolean data type is used to work with Boolean values of true and false. In C#, the datatype is denoted by the Boolean keyword. Below is an example of this datatype can be used.

In our example, we will define a Boolean variable called 'status.' We will then assign a boolean value to the variable and then display it accordingly.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
  { 
   static void Main(string[] args) 
   {
    Boolean status=true;
    Console.Write(status);
    
    Console.ReadKey();
   }
  }
}

Code Explanation:-

  1. The boolean data type is specified to declare a Boolean variable called 'status.' The variable is then assigned a value of true/false.
  2. Finally the console.write function is used to display the Boolean value to the console.
If the above code is entered properly and the program is executed successfully, the output will be displayed.

Output:

From the output, you can clearly see that the Boolean variable which equals true was displayed in the console

4) String

A String data type is used to work with String values. In C#, the datatype is denoted by the keyword 'String'. Below is an example of this datatype.In our example, we will define a String variable called 'message.' We will then assign a String value to the variable and then display it accordingly.







using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class program
 {
  static void Main(string[] args)
  {
   String message="Hello";
   Console.Write(message);
   
   Console.ReadKey();
  }
 }
}

Code Explanation:-

  1. The String data type is specified to declare a string variable called message. The variable is then assigned a value of "Hello".
  2. Finally, the console.write function is used to display the string value to the console.
If the above code is entered properly and the program is executed successfully, the output will be displayed.

Output:

From the output, you can clearly see that the String variable called message was displayed in the console

 

































 








Friday, November 16, 2018

C# Hello World

 

C# Hello World: First Console Application Program              

C# is one of the languages provided by Microsoft to work with .Net. This language encompasses a rich set of features, which allows developing different types of applications.
C# is an object-oriented programming language and resembles several aspects of the C++ Language. In this tutorial, we see how to develop our first application.
This will be a basic console application, we will then explore different data types available in the C# language as well as the control flow statements.

Building the first console application

A console application is an application that can be run in the command prompt in Windows. For any beginner on .Net, building a console application is ideally the first step to begin with.
In our example, we are going to use Visual Studio to create a console type project. Next, we are going to use the console application to display a message "Hello World". We will then see how to build and run the console application.
Let's follow the below mentioned steps to get this example in place.

Step 1) The first step involves the creation of a new project in Visual Studio. For that, once the Visual Studio is launched, you need to choose the menu option New->Project.

Step 2) The next step is to choose the project type as a Console application. Here, we also need to mention the name and location of our project.
  1. In the project dialog box, we can see various options for creating different types of projects in Visual Studio. Click the Windows option on the left-hand side.
  2. When we click the Windows options in the previous step, we will be able to see an option for Console Application. Click this option.
  3. We then give a name for the application which in our case is DemoApplication. We also need to provide a location to store our application.
  4. Finally, we click the 'OK' button to let Visual Studio to create our project.
If the above steps are followed, you will get the below output in Visual Studio.

 Output:-
  1. A project called 'DemoApplication' will be created in Visual Studio. This project will contain all the necessary artifacts required to run the Console application.
  2. The Main program called Program.cs is default code file which is created when a new application is created in Visual Studio. This code will contain the necessary code for our console application.
Step 3) Now let's write our code which will be used to display the string "Hello World" in the console application.

All the below code needs to be entered into the Program.cs file. The code will be used to write "Hello World" when the console application runs.

C# Hello World Program


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
 { 
  static void Main(string[] args) 
  {
   Console.Write("Hello World");

   Console.ReadKey();
  }
 }
}

Code Explanation:-
  1. The first lines of code are default lines entered by Visual Studio. The 'using' statement is used to import existing .Net modules in our console application. These modules are required for any .Net application to run properly. They contain the bare minimum code to make a code work on a Windows machine.
  2. Every application belongs to a class. C# is an object-oriented language, and hence, all code needs to be defined in a self-sustaining module called a 'Class.' In turn, every class belongs to a namespace. A namespace is just a logical grouping of classes.
  3. The Main function is a special function which is automatically called when a console application runs. Here you need to ensure to enter the code required to display the required string in the console application.
  4. The Console class is available in .Net which allows one to work with console applications. Here we are using an inbuilt method called 'Write' to write the string "Hello World" in the console.
  5. We then use the Console.ReadKey() method to read any key from the console. By entering this line of code, the program will wait and not exit immediately. The program will wait for the user to enter any key before finally exiting. If you don't include this statement in code, the program will exit as soon as it is run.
Step 4) Run your .Net program. To run any program, you need to click the Start button in Visual Studio.



 If the above code is entered properly and the program is executed successfully, the following output will be displayed

Output:

From the output, you can clearly see that the string "Hello World" is displayed properly. This is because of the Console.write statement causes this string to be sent to the console.
 
                                     

                                       SHACKINGTRICKS

Thursday, November 15, 2018

How to Download and Install Visual Studio for C#

Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs for Microsoft Windows. Visual Studio is one stop shop for all applications built on the .Net platform. One can develop, debug and run applications using Visual Studio.
Both Forms-based and web-based applications can be designed and developed using this IDE. The Visual Studio has the below-mentioned features

How to Download and Install Visual Studio

Let's look at the download process of Visual Studio IDE so that we can work with creating programs in the subsequent tutorials.
Step 1) Visual Studio can be downloaded from the following
link https://www.visualstudio.com/downloads/
You can select
  • Visual Studio 2017 Community Edition
  • Visual Studio 2017 Professional Edition (30 Day Free Trial)
In this tutorial, we will install the Professional Edition
Step 2) Click on the downloaded exe file
Step 3) In the next screen, click continue

Step 4) Visual Studio will start downloading the initial files. Download speed will vary as per your internet connection.
Step 5) In next screen, click install
Step 6) In next screen,\

  1. Select ".Net desktop development"
  2. Click install
Step 7) Visual Studio will download the relevant files based on the selection in step 6
Step 8) Once the download is done, you will be asked to reboot the PC
Step 9) Post reboot, open the Visual Studio IDE
  1. Select a theme of your choice
  2. Click Start Visual Studio
Step 10) In Visual Studio IDE, you can navigate to File menu to create new C# applications.
That’s it to Visual Studio for C# installation.

Visual Studio Key Features

  1. Creation of an application in any .Net language– The Visual Studio IDE can be used to create an application in any .Net language. Hence, a developer can use C#, VB.Net or even F# to develop an application.
  2. Creation of any application type – The Visual Studio IDE can be used to create an application of any type. (Web-based application or Windows Forms-based application).
  3. Debug Applications on the fly – Applications can be tested as they are being built. The IDE allows one to run the program at any point of time during the development process. Hence, a developer can check for any errors during the development phase itself.
  4. Extensions –The IDE has the facility to install third-party extensions. An example can be Subversion, which is used for source code repository management. Subversion is used to upload code to a central repository. This is done so that a copy of the code will always exist. Visual Studio has the facility to integrate with such software from the IDE itself. Hence, a developer can work with code repositories from the IDE itself.













Wednesday, November 14, 2018

What is .NET Framework?

What is Microsoft .Net Framework?

The .Net framework is a software development platform developed by Microsoft. The framework was meant to create applications, which would run on the Windows Platform. The first version of the .Net framework was released in the year 2002.
The version was called .Net framework 1.0. The .Net framework has come a long way since then, and the current version is 4.7.1.
The .Net framework can be used to create both - Form-based and Web-based applications. Web services can also be developed using the .Net framework.

.Net Framework Architecture

The basic architecture of the .Net framework is as shown below.

.NET Components

The architecture of the .Net framework is based on the following key components;

1. Common Language Runtime

The "Common Language Infrastructure" or CLI is a platform on which the .Net programs are executed.
The CLI has the following key features:
  • Exception Handling - Exceptions are errors which occur when the application is executed. Examples of exceptions are:
    • If an application tries to open a file on the local machine, but the file is not present.
    • If the application tries to fetch some records from a database, but the connection to the database is not valid.
  • Garbage Collection - Garbage collection is the process of removing unwanted resources when they are no longer required. Examples of garbage collection are
    • A File handle which is no longer required. If the application has finished all operations on a file, then the file handle may no longer be required.
    • The database connection is no longer required. If the application has finished all operations on a database, then the database connection may no longer be required.
  • Working with Various programming languages –
As noted in an earlier section, a developer can develop an application in a variety of .Net programming languages.
  1. Language - The first level is the programming language itself, the most common ones are VB.Net and C#.
  2. Compiler – There is a compiler which will be separate for each programming language. So underlying the VB.Net language, there will be a separate VB.Net compiler. Similarly, for C#, you will have another compiler.
  3. Common Language Interpreter – This is the final layer in .Net which would be used to run a .net program developed in any programming language. So the subsequent compiler will send the program to the CLI layer to run the .Net application.


2. Class Library

The .NET Framework includes a set of standard class libraries. A class library is a collection of methods and functions that can be used for the core purpose.
For example, there is a class library with methods to handle all file-level operations. So there is a method which can be used to read the text from a file. Similarly, there is a method to write text to a file.
Most of the methods are split into either the System.* or Microsoft.* namespaces. (The asterisk * just means a reference to all of the methods that fall under the System or Microsoft namespace)


.Net Framework Design Principle

The following design principles of the .Net framework is what makes it very relevant to create .Net based applications.
  1. Interoperability - The .Net framework provides a lot of backward support. Suppose if you had an application built on an older version of the .Net framework, say 2.0. And if you tried to run the same application on a machine which had the higher version of the .Net framework, say 3.5. The application would still work. This is because with every release, Microsoft ensures that older framework versions gel well with the latest version.
  2. Portability- Applications built on the .Net framework can be made to work on any Windows platform. And now in recent times, Microsoft is also envisioning to make Microsoft products work on other platforms, such as iOS and Linux.
  3. Security - The .NET Framework has a good security mechanism. The inbuilt security mechanism helps in both validation and verification of applications. Every application can explicitly define their security mechanism. Each security mechanism is used to grant the user access to the code or to the running program.
  4. Memory management - The Common Language runtime does all the work or memory management. The .Net framework has all the capability to see those resources, which are not used by a running program. It would then release those resources accordingly. This is done via a program called the "Garbage Collector" which runs as part of the .Net framework. The garbage collector runs at regular intervals and keeps on checking which system resources are not utilized, and frees them accordingly.
  5. Simplified deployment - The .Net framework also have tools, which can be used to package applications built on the .Net framework. These packages can then be distributed to client machines. The packages would then automatically install the application.
                                                         
                
https://shackingtricks.blogspot.com/
                                                                           SHACKINGTRICKS


C# Tutorial for Beginners

This tutorial will introduce you to .NET framework using C# language. You will also learn to create a C Sharp based web application using .NET framework. This is a complete online course and covers topics like accessing data, classes & objects, file commands, window forms etc

Syllabus

C# and .Net Version History

Download and Install Visual Studio

C# Hello world

C# Data Types

C# Enum

C# Variables operator

C# Conditional Statements

C# Arrays

C# Class and Object

C# Access Modifiers and Constructor

C# Inheritance and Polymorphism

C# Abstract classes

C# Interface

C# Collections

C# ArrayList

C# Stack

C# Queue

Top 50 C# Interview Questions and Answers

C# Enum (Enumeration)

C# Enumeration An enumeration is used in any programming language to define a constant set of values. For example, the days of the week c...