Variable Scoping and Definite Assignment:Definite Assignment : Variable Definition « Language Basics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Language Basics » Variable DefinitionScreenshots 
Variable Scoping and Definite Assignment:Definite Assignment
Variable Scoping and Definite Assignment:Definite Assignment


using System;
struct Complex
{
    public Complex(float real, float imaginary
    {
        this.real = real;
        this.imaginary = imaginary;
    }
    public override string ToString()
    {
        return(String.Format("({0}, {1})", real, imaginary));
    }
    
    public float    real;
    public float    imaginary;
}

public class DefiniteAssignment3
{
    public static void Main()
    {
        Complex    myNumber1;
        Complex    myNumber2;
        Complex    myNumber3;
        
        myNumber1 = new Complex();
        Console.WriteLine("Number 1: {0}", myNumber1);
        
        myNumber2 = new Complex(5.0F4.0F);
        Console.WriteLine("Number 2: {0}", myNumber2);
        
        myNumber3.real = 1.5F;
        myNumber3.imaginary = 15F;
        Console.WriteLine("Number 3: {0}", myNumber3);
    }
}
           
       
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.declaring a reference type variable and creating an object the variable will reference
23.Definite Assignment and ArraysDefinite Assignment and Arrays
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.