Monday 21 April 2014

C# Type casting

Type conversion is basically type casting or
converting one type of data to another type.

In C#, type casting has two forms:

1. Implicit type conversion - these conversions are performed by C# in a type-safe manner.
                      Examples are conversions from
smaller to larger integral types and
conversions from derived classes to base
classes.

2. Explicit type conversion - these conversionsare done explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.

The following example shows an explicit type
conversion:

namespace TypeConversionApplication
{
class ExplicitConversion
{
static void Main(string[] ar
{
double d = 5673.74 ;
int i ;
// cast double to int.
i = ( int ) d;
Console . WriteLine( i );
Console . ReadKey();
}
}
}

When the above code is compiled and executed, it produces the following result:

5673

**C # Type Conversion Methods
C# provides the following built-in type conversion methods:

S.N Methods & Description
1 .ToBoolean
          Converts a type to a Boolean value, where possible.

2. ToByte
          Converts a type to a byte.

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

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

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

6. ToDouble
           Converts a type to a double type.

7. ToInt16
            Converts a type to a 16-bit integer.

8. ToInt32
            Converts a type to a 32-bit integer.

9. ToInt64
            Converts a type to a 64-bit integer.

10. ToSbyte
           Converts a type to a signed byte type.

11. ToSingle
            Converts a type to a small floating point number.

12. ToString
             Converts a type to a string.

13. ToType
             Converts a type to a specified type.

The following example converts various value types to string type:

namespace TypeConversionApplication
{
class StringConversion
{
static void Main(string[] ar
{
int i = 75;
float f = 53.005f ;
double d = 2345.7652 ;
bool b = true;
Console . WriteLine( i . ToSt
Console . WriteLine( f . ToSt
Console . WriteLine( d . ToSt
Console . WriteLine( b . ToSt
Console . ReadKey();
}
}
}

When the above code is compiled and executed, it produces the following result:

75
53.005
2345.7652
True

Compiling and executed a c# program

If you are using Visual Studio.Net for compiling and executing C# programs, take the following steps:
1. Start Visual Studio.

2. On the menu bar, choose File, New, Project.

3. Choose Visual C# from templates, and then  choose Windows.

4. Choose Console Application.

5. Specify a name for your project, and then choose the OK button.

6. The new project appears in Solution Explorer.

7. Write code in the Code Editor.

8. Click the Run button or the F5 key to run the project. A Command Prompt window appears that contain the line Hello World.

You can compile a C# program by using the
command-line instead of the Visual Studio IDE:

* Open a text editor and add the above- mentioned code.

* Save the file as helloworld.cs

* Open the command prompt tool and go to the directory where you saved the file.

* Type csc helloworld.cs and press enter to compile your code.

* If there are no errors in your code, the command prompt will take you to the next line and would generate helloworld.exe executable file.

* Next, type helloworld to execute your program.

* You will be able to see "Hello World" printed on the screen.

SAP HANA DB ANALYSIS AFTER ISSUES

To be able to further analyze your issue and environment please download the attached shell script you can get from KBA: 3218277 - Collectin...