Assigning array reference variables : Array « Collections Data Structure « 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 » Collections Data Structure » ArrayScreenshots 
Assigning array reference variables
Assigning array reference variables
 
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Assigning array reference variables. 
 
using System; 
 
public class AssignARef {  
  public static void Main() {  
    int i; 
 
    int[] nums1 = new int[10]
    int[] nums2 = new int[10]
 
    for(i=0; i < 10; i++nums1[i= i; 
 
    for(i=0; i < 10; i++nums2[i= -i; 
 
    Console.Write("Here is nums1: ")
    for(i=0; i < 10; i++
      Console.Write(nums1[i" ");   
    Console.WriteLine()
 
    Console.Write("Here is nums2: ")
    for(i=0; i < 10; i++
      Console.Write(nums2[i" ");   
    Console.WriteLine()
 
    nums2 = nums1; // now nums2 refers to nums1 
 
    Console.Write("Here is nums2 after assignment: ")
    for(i=0; i < 10; i++
      Console.Write(nums2[i" ");   
    Console.WriteLine()
 
   // now operate on nums1 array through nums2 
   nums2[399
 
    Console.Write("Here is nums1 after change through nums2: ")
    for(i=0; i < 10; i++
      Console.Write(nums1[i" ");   
    Console.WriteLine()
  }  
}

           
         
  
Related examples in the same category
1.Demonstrate a one-dimensional arrayDemonstrate a one-dimensional array
2.Declare all kinds of arrays
3.Compute the average of a set of valuesCompute the average of a set of values
4.Enumerates an array using an enumerator object
5.Compute the average of a set of values 2Compute the average of a set of values 2
6.Demonstrate an array overrun
7.Use the Length array propertyUse the Length array property
8.Reverse an array 2Reverse an array 2
9.illustrates how to use arrays 2illustrates how to use arrays 2
10.illustrates an attempt to write to a nonexistent array elementillustrates an attempt to write to a nonexistent array element
11.illustrates how to initialize arraysillustrates how to initialize arrays
12.illustrates how to use array properties and methodsillustrates how to use array properties and methods
13.illustrates the use of an array of objectsillustrates the use of an array of objects
14.Uses the Array.Copy() method to copy part of an array ints into a secton of an array of doublesUses the Array.Copy() method to copy part of an array ints into a secton of an array of doubles
15.Creates and implements an instance of ArrayCreates and implements an instance of Array
16.Stores a sequence of temperatures in an arrayStores a sequence of temperatures in an array
17.Creates an and array and looks for the index of a given value from either endCreates an and array and looks for the index of a given value from either end
18.Sums the values in an array using a foreach loop 1Sums the values in an array using a foreach loop 1
19.Uses the Array.Copy() method to copy an array of ints into an array of doubles 2Uses the Array.Copy() method to copy an array of ints into an array of doubles 2
20.Class array init
21.Class arrayClass array
22.Multi Dimensional ArraysMulti Dimensional Arrays
23.Jagged Array DemoJagged Array Demo
24.Array reverse and sortArray reverse and sort
25.Use object to create a generic arrayUse object to create a generic array
26.Sort an array and search for a valueSort an array and search for a value
27.Sort and search an array of objectsSort and search an array of objects
28.Reverse an arrayReverse an array
29.Copy an arrayCopy an array
30.Array ConversionsArray Conversions
31.Arrays of Reference Types
32.System.Array Type:ReverseSystem.Array Type:Reverse
33.Array.Sort by CultureInfo
34.A run-time error occurs when Array.Sort is called: XClass does not implement the IComparable interface.
35.Array.SyncRoot Property: synchronize access to an array.
36.Array.Resize Method
37.Array.FindAll Method: This is the syntax of the Predicate delegate:delegate bool Predicate(T obj)
38.Array.CreateInstance Method
39.Array.Clone Method
40.Array.AsReadOnly Method
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.