Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

C# data types

Quickly covers C#'s data types by giving a few examples. Good for transition between C or C++ to C#.

On Saturday, April 3rd 2004 at 05:50 PM
By Andrew Pociu (View Profile)
***--   (Rated 3 with 17 votes)
Contextual Ads
More C# Resources
Advertisement

C# Data Types



The following example will show you the information you need about C#'s data types:


// DataTypes.cs
using System;
    class DataTypes
    {
        static void Main()
        {
            Console.WriteLine("The minimum and maximum sizes of C#'s datatypes:\n");
            Console.WriteLine("sbyte\nMin: {0}\nMax: {1}\n", sbyte.MinValue, sbyte.MaxValue);
            Console.WriteLine("byte\nMin: {0}\nMax: {1}\n", byte.MinValue, byte.MaxValue);
            Console.WriteLine("short\nMin: {0}\nMax: {1}\n", short.MinValue, short.MaxValue);
            Console.WriteLine("ushort\nMin: {0}\nMax: {1}\n", ushort.MinValue, ushort.MaxValue);
            Console.WriteLine("int\nMin: {0}\nMax: {1}\n", int.MinValue, int.MaxValue);
            Console.WriteLine("uint\nMin: {0}\nMax: {1}\n", uint.MinValue, uint.MaxValue);
            Console.WriteLine("long\nMin: {0}\nMax: {1}\n", long.MinValue, long.MaxValue);
            Console.WriteLine("ulong\nMin: {0}\nMax: {1}\n", ulong.MinValue, ulong.MaxValue);
            Console.WriteLine("float\nMin: {0}\nMax: {1}\n", float.MinValue, float.MaxValue);
            Console.WriteLine("double\nMin: {0}\nMax: {1}\n", double.MinValue, double.MaxValue);
            Console.WriteLine("decimal\nMin: {0}\nMax: {1}\n", decimal.MinValue, decimal.MaxValue);
            Console.ReadLine(); // Keep the console opened until you press Enter
        }
    }



The output of the program is:


The minimum and maximum sizes of C#'s datatypes:

sbyte
Min: -128
Max: 127

byte
Min: 0
Max: 255

short
Min: -32768
Max: 32767

ushort
Min: 0
Max: 65535

int
Min: -2147483648
Max: 2147483647

uint
Min: 0
Max: 4294967295

long
Min: -9223372036854775808
Max: 9223372036854775807

ulong
Min: 0
Max: 18446744073709551615

float
Min: -3.402823E+38
Max: 3.402823E+38

double
Min: -1.79769313486232E+308
Max: 1.79769313486232E+308

decimal
Min: -79228162514264337593543950335
Max: 79228162514264337593543950335



sbyte is the signed version of byte (8 bits);
short is the signed version of ushort (16 bits);
int is the signed version of uint (32 bits);
long is the signed version of ulong (64 bits);

The 'char' type stores a single character;
The 'string' data type stores multiple characters;

Getting the length of a string


Suppose you have the 'content' variable that is a 'string' type of variable:


string content = "The actual string";



You can find the length of this string using:


content.Length



For example:


using System;
    class StringLength
    {
        static void Main()
        {
            string Content = "The actual string";
            Console.WriteLine("{0}\n", Content);
            Console.WriteLine("The length of the above string is {0} characters", Content.Length);
            Console.ReadLine(); // Keep the console opened until you press Enter
        }
    }



The 'float' data type is 32 bits long. It has an 8 bits long exponent and 24 bits long mantissa;
The 'double' data type is 64 bits long. It has an 11 bits long exponent and 53 bits long mantissa;

C# arrays



You can initialize an array using:


int[] objects;



If you want to allocate a space in memory for the elements of the array use:


int[] objects = new int[5];



or separate:


int[] objects;
objects = new int[5];



This is a complete example of initializing an array and accessing it using a loop:


using System;

    class Arrays
    {
        static void Main()
        {
            char[] website = new char[9] {'G', 'e', 'e', 'k', 'p', 'e', 'd', 'i', 'a'};
            int i = 0;
            for (i = 0; i < website.Length; i++)
            {
            Console.Write("{0}", website[i]);
            }
        Console.ReadLine();
        }
    }


(The above example could be simplified by using a 'foreach' loop like in VB but I wanted to stick to the topic).
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by wrong on Monday, November 21st 2005 at 02:39 PM

float is actually 8 bits exponent, 23 bits mantissa, 1 sign bit

by dileep S on Wednesday, September 13th 2006 at 01:09 AM


There is any maximum limit for string . if so what is that ?

by praveenkumarpathak on Friday, December 14th 2007 at 06:50 AM

please program my hand over me.

praveen kumar pathak

by Corey Ogburn on Monday, May 19th 2008 at 04:39 PM

This subject has been thrown around a little at the office here recently. We agreed that all arrays have one limit, the index has to be an integer. Therefore, the array can't be bigger then an integer value can hold ( 2147483647). So roughly 2 GBs. We agree even more so that you'll run out of RAM long before you'll run out of array length. ha ha

by wedding wishes on Sunday, August 14th 2011 at 06:30 AM

What I needed to pair is why you didnt try to imprimatur the new superior of this payment ? There are so numerous things that youre absent here that I dont see how you could actually descriptor an penetrating sight on the feudatory. Its synoptic you didnt plane ruminate that there me be separate withdraw here.

by kids stories on Sunday, August 14th 2011 at 01:38 PM

Pretty informal substance. I pianoforte stumbled upon your ledger and hot to say that I possess arts enjoyed substance your book posts. Any way I'll be subscribing to your cater and I draftsmanship you publicise again presently

by kids stories on Sunday, August 14th 2011 at 01:38 PM

Pretty informal substance. I pianoforte stumbled upon your ledger and hot to say that I possess arts enjoyed substance your book posts. Any way I'll be subscribing to your cater and I draftsmanship you publicise again presently

by love sms on Tuesday, August 16th 2011 at 12:10 AM

his subject has been thrown around a little at the office here recently. We agreed that all arrays have one limit, the index has to be an integer. Therefore, the array can't be bigger then an integer value can hold ( 2147483647). So roughly 2 GBs. We agree even more so that you'll run out of RAM long before you'll run out of array length. ha ha.

by heartburn diet on Friday, August 19th 2011 at 09:29 PM

Succeed you for writer nonsynthetic article. Where encourage could anyone get that kind of scheme in ofttimes a sum way of utilise ? I conversation a take drawn bind, and I am on the spotter for copiousness forgather.

by heartburn symptoms on Thursday, October 6th 2011 at 09:16 AM

Smooth I definitely liked naming it. This info provided by you is rale manufacture for prudish cerebration.
<a href="http://www.heartburny.com/heartburn-symptoms/">heartburn symptoms</a>

by heartburn symptoms on Thursday, October 6th 2011 at 09:16 AM

Smooth I definitely liked naming it. This info provided by you is rale manufacture for prudish cerebration.
<a href="http://www.heartburny.com/heartburn-symptoms/">heartburn symptoms</a>

by heartburn symptoms on Thursday, October 6th 2011 at 10:32 AM

Smooth I definitely liked naming it. This info provided by you is rale manufacture for prudish cerebration.
<a href="http://www.heartburny.com/heartburn-symptoms/">heartburn symptoms</a>

by usmankowja on Saturday, October 8th 2011 at 01:42 AM

This is a wonderful orientating. I enjoyed the entropy lot. I noesis signification this authorised. Thanks for method this one connecter.
<a href="http://www.offshoreletter.com/do-you-need-an-offshore-services-company/">offshore company </a>

by Jan Baptysta on Tuesday, January 24th 2012 at 05:47 AM

Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia
Other Resources
Bargain EZ Tech Coupons & Deals