Personalized lock screen

Microsoft Windows 8 Personalized lock screen. from windows.microsoft.com

The tiles of the Start screen

Microsoft Windows 8 The tiles of the Start screen from windows.microsoft.com.

Touch keyboard

Microsoft Windows 8 Touch keyboard from windows.microsoft.com.

Showing posts with label Basic. Show all posts
Showing posts with label Basic. Show all posts

What is c# / What is C sharp


C sharp


C# is a software design and programming language which enables object oriented concepts. It is invented around 1999 or 2000 by Anders Hejlsberg at Microsoft.

C# is designed to work with Microsoft's .Net platform.

It is very similar to java. But C# does not support multiple inheritance. It provides interfaces. Interfaces implemented by a class specify certain functions that the class is guaranteed to implement.

 Interfaces avoid the multiple inheritance while maintaining the ability to let several classes implement the same set of methods.

Microsoft .NET Framework 4

Another useful feature of C# is garbage collection. Therefore, it is unnecessary to add a destructor for each class unless a class handles unmanaged resources.  If so, it's necessary to release control those resources from within the class.

C# also provides direct access to memory through C++ style pointers, but these pointers are not garbage collected until specifically released by the programmer.

In C#, .NET framework, programmer’s code is compiled in to MSIL (Microsoft Intermediate Language) which is similar to the java bitecode.

MSIL allows C# to be platform independent and runs using just in time compiling.

The MSIL is what allows C# to be platform independent like bytecode.

What are the Variables and Variable Types in C sharp


"Variables" are simply storage locations for data in program. Programmer is able to place data into variable and retrieve their contents. The interpretation of the data in a variable is controlled through "Types".

The C# simple types consist of the Boolean, Integrals, Floating Point, Decimal and String. In integrals types includes sbyte, byte, short, int, uint, long, and char.

In “Floating Point" refers to the float and double types


The Boolean Type
Boolean types are declared using the keyword, bool. They have two values: true or false.
          bool state = true;
        bool noState = false;


Integral Types
They are whole numbers, either signed or unsigned. Integral types are well suited for those operations involving whole number calculations.

The Size and Range of C# Integral Types
Type
Size (in bits)
Range
sbyte
8
-128 to 127
byte
8
0 to 255
short
16
-32768 to 32767
ushort
16
0 to 65535
int
32
-2147483648 to 2147483647
uint
32
0 to 4294967295
long
64
-9223372036854775808 to 9223372036854775807
ulong
64
0 to 18446744073709551615





Floating Point and Decimal Types
In C# floating point type is either a float or double. Floating point types are used when you need to perform operations requiring fractional representations.

The Floating Point and Decimal Types with Size, precision, and Range
Type
Size (in bits)
precision
Range
float
32
7 digits
1.5 x 10-45 to 3.4 x 1038
double
64
15-16 digits
5.0 x 10-324 to 1.7 x 10308
decimal
128
28-29 decimal places
1.0 x 10-28 to 7.9 x 1028



The string Type
A string is a collection of characters. This type allows us to manipulate character data through methods and properties. It provides methods to concatenate, append, replace, search and split.


String has the following characteristics

  1. It is a reference type – string is not a value type. It is a reference type.
  2. It's immutable - You can never change the contents of a string. If you try to do, it just sets the value of string to a new string, which is a copy of the old string.
  3. It can contain nulls - In .NET, strings can contain null characters with no problems at all as far as the string methods themselves are concerned
  4. It overloads by the == operator - When the == operator is used to compare two strings, the Equals method is called




What is Enumeration or Enums


In this c sharp question, we will discuss about Enumerations.

Enumeration or Enums store special values. They make programs simpler by providing an efficient way to define a set of constants which they may be assigned to a variable. If you use constants directly to do this, your C# program rapidly becomes complex and hard to change. Enumeration will provide you to keep these magic constants in a distinct type. This improves code clarity and alleviates maintenance issues.

As an example if you define a variable which will represent a day of week then there are only seven meaningful values. To define those values, you can use an enumeration type, which is declared by using the enum keyword.

enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

By default type of each element in the enum is int. if you need to specify another type then you need to implement it by using a colon, as shown in the bellow example

enum Days : byte { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

If you do not specify values for the each element in the list the values are automatically incremented by one. Like

Days.Sunday has a value of     0
Days.Monday has a value of    1
And so on.


class Program
    {
        enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

        static void Main(string[] args)
        {
            // These values are enum Days types.
            Days weekend_ = Days.Saturday;

            if (weekend_ == Days.Saturday)
            {
                // Will be printed.
                Console.WriteLine("Today is Weekend");
            }

            if (weekend_ == Days.Sunday)
            {
                // Will not be printed.
                Console.WriteLine("Today is Weekend");
            }
        }
    }


And also you can assign any values to the elements in the enumerator list of an enumeration type, and you can also use computed values at the program.

enum MyDayPlan
{
    Getup = 5,
    Schooling = 8,
    Swimming = 5,
    Eating = Swimming + 2
}




How to use savefiledialog box in the c#.net ?

// Create a new SaveFileDialog object
SaveFileDialog obDialogSave = new SaveFileDialog();

// Set Default file extension to dialog
obDialogSave.DefaultExt = "txt";

// Other Available file extensions to dialog
obDialogSave.Filter = "Text file (*.txt)|*.txt|XML file (*.xml)|*.xml|All files (*.*)|*.*";

// Adds a extension if the user does not select
obDialogSave.AddExtension = true;

// Restores the selected directory, next time
obDialogSave.RestoreDirectory = true;

// To display Dialog title
obDialogSave.Title = "Where do you want to save the file?";

// Start directory
obDialogSave.InitialDirectory = @"C:/";

// Show the dialog and process the result
if (obDialogSave.ShowDialog() == DialogResult.OK)
{
// your code go here if user click on “OK” button.
MessageBox.Show("You selected the file: " + DialogSave.FileName);
}
else {
// your code go here if user click on “Cancel” button.
MessageBox.Show("You click cancel.");
}

obDialogSave.Dispose();

// Set object to null.
obDialogSave = null;

What is .Resx file in Dot Net?

What is .Resx file in Dot Net? How to access?

Resource files are used in .NET to store culture-specific data all in one place, separate from the code. For example, suppose you are developing a multi-language Web site and you have a form on a page with a label beside a text field and the label in English says "First Name." Instead of having code like this:

if (language == "English")
{
lblFirstName = "First Name";
}
else if (language == "German")
{
lblFirstName = "Vorname";
}
You can just do this:

ResourceManager resourceManager = new ResourceManager("nameSpace.resourceFileBaseName",
Assembly.GetExecutingAssembly());
lblFirstName = resourceManager.GetString("lblFirstName");
And that's it—just two lines. There's no need to change a million sections of code each time you add or take away a language.


Reading from .Resx File:

You can access the .Resx file using this code:

ResXResourceReader reader = new ResXResourceReader(Server.MapPath("fileName.resx"));
IDictionaryEnumerator rsxr = reader.GetEnumerator();
foreach (DictionaryEntry d in reader)
{
Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
}
//Close the reader.
reader.Close();

Writing to .Resx File:

We can write the binary data of an image to the .Resx file using the following code

Image img = Image.FromFile("abc.jpg");
ResXResourceWriter rsxw = new ResXResourceWriter("abc.resx");
rsxw.AddResource("urdu.jpg",img);
rsxw.Close();

Use of .Resx File:

It is very useful while working on Localized project [Multiple Languages], You can make different resource files for different languages and depending upon the user choice you can change the Language of the application.