Breaking News

C#.net simplified in short !! brush up before interview!!

I thought of simplifying the whole c# into a small paragraph (i m working now to make it short)so that you can brush up when you go for any interviews.

Only things that you need to know about c# is use of variable,how to classes and combine it, use properties inside class,use oops 4 concepts of classes,built in classes,data reading and formating,how to create methods and use it,use conditional statements like switches and statements, structures, delegates, exceptions and arrays.

Use comments like //, /* ,*/

In the option menu of project you can change the color,indentation etc...

These are keywords !!

abstract const extern int out short typeof
as continue false interface override sizeof uint
base decimal finally internal params stackalloc ulong
bool default fixed is private static unchecked
break delegate float lock protected string unsafe
byte do for long public struct ushort
case double foreach namespace readonly switch using
catch else goto new ref this virtual
char enum if null return throw void
checked event implicit object sbyte true volatile
class explicit in operator sealed try while

contextual keywords
get partial set value where yield

To display a value in dark window, you can enter it in the parentheses of the Console.Write() or Console.WriteLine(). Here is example:

using System;

class Program
{
static void Main()
{
Console.WriteLine(248);
Console.Write(1);
}
}

Suppose u want to write some symbols in cmd u have to use these conversions with writeline:

Dec Bin Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

Example :

using System;

class Exercise
{
static void Main()
{
var Number = 0xFE;

Console.Write("Number: ");
Console.WriteLine(Number);
}
}

If u want to store more in a variable use double word that 32 bit instead 16 of ordinary variable:

using System;

class Exercise
{
static void Main()
{
var Population = 72394475;

Console.Write("Country Population: ");
Console.WriteLine(Population);
}
}
This would produce:

Country Population: 72394475
Press any key to continue . . .

Or...

If you declare an integer variable using the var keyword and initialize it with a value lower than 2,147,484,647, the compiler concludes that the memory needed to store that variable is 32 bits:


Class is a technique of using one or a group of variables to be used as a foundation for a more detailed variable.

class Program
{
static void Main()
{
int bedrooms = 3;
}
}

u can also use add class from designer and view using class view box.

If you want your class to be accessible to code written in other languages, precede the class keyword with public when creating it

When you initialize a variable using the new operator, you are in fact reserving some space in the heap memory. The memory is "allocated" for the variable. When that variable is no longer needed, such as when your program closes, it (the variable) must be removed from memory and the space it was using can be made available to other variables or other programs. This is referred to as garbage collection.

The variables declared in the body of a class are referred to as its member variables and each member variable is referred to as a field.

The public and private keywords are referred to as access level.


We saw that, to use a class, you could first declare a variable for it and initialize it. Fortunately, you don't have to use a class to initialize an object. You can declare a variable that resembles an instance of a class and initialize it as you see fit. This is referred to as an anonymous type. To use it, declare the variable using the var keyword and use the new operator to allocate memory for it

using System;

public class Exercise
{
static void Main()
{
var BookInformation = new
{
Title = "Calculus 6e Edition",
Pages = 1074,
Cover = "Hard Back"
};

Console.WriteLine("=//= BookInformation =//=");
Console.Write("Title: ");
Console.WriteLine(BookInformation.Title);
Console.Write("Nbr of Pages: ");
Console.WriteLine(BookInformation.Pages);
Console.Write("Type of Cover: ");
Console.WriteLine(BookInformation.Cover);
}
}
This would produce:

=//= BookInformation =//=
Title: Calculus 6e Edition
Nbr of Pages: 1074
Type of Cover: Hard Back
Press any key to continue . . .

If an object can also perform actions or assignments. An action performed by a class is called a method

public class House
{
public char PropertyType;
public uint Bedrooms;

public void Display()
{
Console.WriteLine("=//= Altair Realty =//=");
Console.WriteLine("Properties Inventory"); ;
Console.Write("Property Type: ");
Console.WriteLine(PropertyType);
Console.Write("Bedrooms: ");
Console.WriteLine(Bedrooms);
}
}

use code editor for view methods.
The right combo box, named Members, displays the members of the class
The Solution Explorer is a window that displays the file names and other items used in your project.
C# allows you to declare a class member and refer to it regardless of which instance of an object you are using. Such a member variable is called static.
Like a member variable, a method of a class can be defined as static.

create a constant variable using const keyword.

Using the this member variable (in C/C++, it is a pointer), you can access any member of a class within any method of the same class

A namespace is a section of code that is identified with a specific name.
namespace Business
{
class House
{
}
}
use the period operator to access an item that is part of the namespace

using System;

namespace Business
{
public class House
{
public string PropertyNumber;
public decimal Price;
}
}

class Program
{
static void Main()
{
Business.House property = new Business.House();

property.PropertyNumber = "D294FF";
property.Price = 425880;

Console.WriteLine("=//= Altair Realty =//=");
Console.WriteLine("Properties Inventory");
Console.Write("Property #: ");
Console.WriteLine(property.PropertyNumber);
Console.Write("Market Value: ");
Console.WriteLine(property.Price);
Console.WriteLine();
}
}
This would produce:

=//= Altair Realty =//=
Properties Inventory
Property #: D294FF
Market Value: 425880

Press any key to continue . . .

compiler of the Microsoft .NET Framework is a program called csc
use this :
csc Filename.cs
compiler to produce an executable using the name of your choice
csc /out:NameOfExecutate.exe Filename.cs


If you want to use a pointer in your application, you must precede the name of every method that uses unsafe code with the unsafe keyword.

using System;

class Exercise
{
unsafe static void Main()
{
int Length = 224;
int *Len = &Length;

Console.Write("Length ");
Console.WriteLine(Length);
Console.Write("Length ");
Console.WriteLine(*Len);
Console.WriteLine();

Length = 804;
Console.Write("Length ");
Console.WriteLine(Length);
Console.Write("Length ");
Console.WriteLine(*Len);
}
}


csc /unsafe Exercise.cs


The + button allows you to expand a hidden code section

instead of, the sections of code created by the Code Editor, if you want, you can create your own sections. To do this, start the section with

#region Whatever
and end it with

#endregion Whatever

You don't have to type anything on the right side of #endregion. After creating the region, the Code Editor would display a - button to the left side of #region with a line from there to the left of #endregion:

Console class provides the Read() method to get a value from the user
VariableName = Console.Read();

ReadLine()

After getting the string, you must convert it to a number. To perform this conversion, each data type of the .NET Framework provides a mechanism called Parse.

the user has entered the string you can then convert it to a DateTime value

DateTime OrderDate, OrderTime;
Console.Write("Enter the order date(mm/dd/yyyy): ");
OrderDate = DateTime.Parse(Console.ReadLine());
Console.Write("Enter the order time(hh:mm AM/PM): ");
OrderTime = DateTime.Parse(Console.ReadLine());
Console.WriteLine("Order Date: {0:D}", OrderDate);
Console.WriteLine("Order Time: {0:t}", OrderTime);






strNumber = Console.ReadLine();
Number = int.Parse(strNumber);

To properly display data in a friendly and most familiar way, you can format it. Formatting tells the compiler what kind of data you are using and how you want the compiler to display it to the user. As it happens, you can display a natural number in a common value or, depending on the circumstance, you may prefer to show it as a hexadecimal value.

Character Used For
c C Currency values
d D Decimal numbers
e E Scientific numeric display such as 1.45e5
f F Fixed decimal numbers
g G General and most common type of numbers
n N Natural numbers
r R Roundtrip formatting
x X Hexadecimal formatting
p P Percentages

Here are examples:

using System;

public class Exercise
{
public static void Main()
{
var Distance = 248.38782;
var Age = 15;
var NewColor = 3478;
var HSalary = 22.74;
var HoursWorked = 35.5018473;
var WeeklySalary = HSalary * HoursWorked;

Console.WriteLine("Distance: {0}", Distance.ToString("E"));
Console.WriteLine("Age: {0}", Age.ToString());
Console.WriteLine("Color: {0}", NewColor.ToString("X"));
Console.WriteLine("Weekly Salary: {0} for {1} hours",
WeeklySalary.ToString("c"),
HoursWorked.ToString("F"));

Console.WriteLine();
}
}
This would produce:

Distance: 2.483878E+002
Age: 15
Color: D96
Weekly Salary: $807.31 for 35.50 hours


Variable declared in the body of a method is referred to as a local variable

Program.cs file is the mail file in an application. The programs starts from this file.

static int Main() --> this is the main method!!

Passing an Argument by Value

When you declare a variable in a program, the compiler reserves an amount of space for that variable. If you need to use that variable somewhere in your program, you call it and make use of its value. There are two major issues related to a variable: its value and its location in the memory. The location of a variable in memory is referred to as its address.

When you declare a variable in a program, the compiler reserves an amount of space for that variable. If you need to use that variable somewhere in your program, you call it and make use of its value. There are two major issues related to a variable: its value and its location in the memory. The location of a variable in memory is referred to as its address.

using System;

class Exercise
{
static void Initializer(out double n)
{
n = 128.44;
}

public static int Main()
{
double Number = 15.25;

Console.WriteLine("Number = {0}", Number);
Initializer(out Number);
Console.WriteLine("Number = {0}", Number);
return 0;
}
}
This would produce:

Number = 15.25
Number = 128.44

ability to have various methods with the same name in the same program is referred to as method overloading. To perform overloading, the methods must have different numbers or different type(s) of arguments.

constructor:
var flr = new Flower();

If you declare a variable of a class in your program, when the program comes up, the compiler reserves enough memory space for each member of the class. The memory space reserved for each member variable is filled with an initial value based on its type. For a string object, the space would be left empty. For an integer type, the space would be filled with 0. A better way to take care of this type is to provide a value whose role would be to initialize the member variables with the values of your choice. A method that initializes an object can return any value but it is preferable to be of type void because its primary purpose is to reset the values.
A constructor is a special method that is created when the object comes to life. This particular method holds the same name as the class and it initializes the object whenever that object is created. When you create a class, if you don't declare a constructor, the compiler creates one for you; this is useful because it lets all other objects of the program know that the object exists. This compiler-created constructor is called the default constructor. If you want, you can create your own constructor.

To create a constructor, declare a method that holds the same name as the class. Remember that the method must not return any value.

Here is an example:

namespace FlowerShop
{
public class Flower
{
Flower()
{
}
}
}
A constructor can be used to initialize the member variables of a class
A destructor does the cleaning behind the scenes. Like the default constructor, the compiler always creates a default destructor if you don't create one.
~Flower()
{
}
A class can be created inside of another class.
public class Outside
{
public class Inside
{
}
}

Boolean Variables

When interacting with a computer, a user submits values to a running application. Some of these values are valid. Some other values must be rejected or changed. To take care of these, the values must be checked, examined, re-examined, etc. The validity of a value is checked against its type. For example, a number can be checked as being equal to another. A condition can be checked as being true. A measure can be checked as to whether it is higher than a certain threshold
Boolean TheFloorIsCoveredWithCarpet;

A variable is referred to as Boolean if it can hold a value that is either true or false. To declare a Boolean variable, you can use either the var or the bool keyword. Here is an example:

using System;

public class Exercise
{
static int Main()
{
bool DrinkingUnderAge;
}
}



Please circulate this link don't be pessimistic!!

No comments