Define struct and use it : struct « Class Interface « C# / C Sharp






Define struct and use it

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 */
using System;

namespace Client.Chapter_3___Structs__Enums__Arrays_and_Classes
{
  public struct MyStruct
  {
    public int MyInt;
    public long MyLong;
    public string MyString;
  }
  public class StructsChapter_3___Structs__Enums__Arrays_and_Classes
  {
    static void Main(string[] args)
    {
      MyStruct TheStruct;

      TheStruct.MyInt = 0;
      TheStruct.MyLong = 0;
      TheStruct.MyString = "Hello World";
    }
  }
}

           
       








Related examples in the same category

1.Structs And Enums
2.Demonstrate a structureDemonstrate a structure
3.Copy a structCopy a struct
4.Structures are good when grouping dataStructures are good when grouping data
5.demonstrates a custom constructor function for a structuredemonstrates a custom constructor function for a structure
6.Defining functions for structs
7.demonstrates using a structure to return a group of variables from a functiondemonstrates using a structure to return a group of variables from a function
8.Demonstates assignment operator on structures and classes.Demonstates assignment operator on structures and classes.
9.Issue an error message if you do not initialize all of the fields in a structure
10.Illustrates the use of a structIllustrates the use of a struct
11.C# always creates a structure instance as a value-type variable even using the new operatorC# always creates a structure instance as a value-type variable even using the new operator
12.Calling a Function with a Structure ParameterCalling a Function with a Structure Parameter
13.Structs (Value Types):A Point StructStructs (Value Types):A Point Struct
14.Structs (Value Types):Structs and ConstructorsStructs (Value Types):Structs and Constructors
15.Conversions Between Structs 1
16.Conversions Between Structs 2