Read Int 24 from byte array

image_pdfimage_print

//http://walkmen.codeplex.com/license
// License: GNU General Public License version 2 (GPLv2)

using System;
using System.Collections.Generic;
using System.Text;

namespace Walkmen.Util
{
public sealed class NumericUtils
{
private NumericUtils()
{
}

public static int ReadInt24(byte[] buffer, int offset)
{
return (buffer[offset + 0] << 16) + (buffer[offset + 1] << 8) + (buffer[offset + 2]); } } } [/csharp]

Write short value to byte array

image_pdfimage_print
   
 
//http://walkmen.codeplex.com/license
// License:  GNU General Public License version 2 (GPLv2)  


using System;
using System.Collections.Generic;
using System.Text;

namespace Walkmen.Util
{
    public sealed class NumericUtils
    {
        private NumericUtils()
        {
        }

        public static byte[] WriteShort(short value)
        {
            byte[] result = new byte[2];
            result[0] = (byte)((value &amp; 0xFF00) >> 8);
            result[1] = (byte)((value &amp; 0x00FF));

            return result;
        }
   }
}

   
     


Read short from byte array

image_pdfimage_print

//http://walkmen.codeplex.com/license
// License: GNU General Public License version 2 (GPLv2)

using System;
using System.Collections.Generic;
using System.Text;

namespace Walkmen.Util
{
public sealed class NumericUtils
{
private NumericUtils()
{
}

public static short ReadShort(byte[] buffer, int offset)
{
return (short)((buffer[offset + 0] << 8) + buffer[offset + 1]); } } } [/csharp]

Use byte

image_pdfimage_print

/*
C#: The Complete Reference
by Herbert Schildt

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Use byte.

using System;

public class Use_byte {
public static void Main() {
byte x;
int sum;

sum = 0;
for(x = 1; x <= 100; x++) sum = sum + x; Console.WriteLine("Summation of 100 is " + sum); } } [/csharp]

Box to object

image_pdfimage_print
   
 

class MyBoxingClass
{
    public static void DisplayMyCollection(params object[] anArray)
    {
        foreach (object obj in anArray)
        {
            System.Console.Write(obj + "	");
        }

        // Suspend the screen.
        System.Console.ReadLine();
    } 

    static void Main()
    {
        DisplayMyCollection(101, "Visual C# Basics", 2002);
    }
}