declaring a reference type variable and creating an object the variable will reference : Variable Definition « Language Basics « C# / C Sharp






declaring a reference type variable and creating an object the variable will reference

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
// RefType.cs -- Demonstrate declaring a reference type variable
//               and creating an object the variable will reference.
//
//               Compile this program with the following command line:
//                   C:>csc RefType.cs
using System;
using System.IO;

namespace nsRefType
{
    public class RefType123
    {
        static public void Main ()
        {
// Declare the reference type variable
            FileStream strm;
// Create the object the variable will reference
            strm = new FileStream ("./File.txt",
                                   FileMode.OpenOrCreate,
                                   FileAccess.Write);
        }
    }
}

           
       








Related examples in the same category

1.Declaring a variable.
2.Initializing a variable.
3.Variable default nameVariable default name
4.Heap and Stack Memory
5.Two reference type variables may refer (or point) to the same objectTwo reference type variables may refer (or point)
               to the same object
6.Create a 4-bit type called NybbleCreate a 4-bit type called Nybble
7.Use new with a value typeUse new with a value type
8.Init variableInit variable
9.An attempt to reference an uninitialized variable
10.Illustrates variable scope
11.Demonstrate the use of readonly variablesDemonstrate the use of readonly variables
12.Uninitialized Values
13.Int, float, double, decimalInt, float, double, decimal
14.Demonstrate dynamic initializationDemonstrate dynamic initialization
15.Demonstrate block scopeDemonstrate block scope
16.Demonstrate lifetime of a variableDemonstrate lifetime of a variable
17.This program attempts to declared a variable in an inner scope
18.Demonstrate castingDemonstrate casting
19.A promotion surpriseA promotion surprise
20.Using casts in an expressionUsing casts in an expression
21.Create an implication operator in C#Create an implication operator in C#
22.Definite Assignment and ArraysDefinite Assignment and Arrays
23.Variable Scoping and Definite Assignment:Definite AssignmentVariable Scoping and Definite Assignment:Definite Assignment