Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem with arrays... Pin
Jeff Varszegi12-Mar-04 9:00
professionalJeff Varszegi12-Mar-04 9:00 
QuestionRecord types in C# ? Pin
Andres Coder3-Feb-04 19:59
Andres Coder3-Feb-04 19:59 
AnswerRe: Record types in C# ? Pin
John Kuhn3-Feb-04 20:18
John Kuhn3-Feb-04 20:18 
GeneralRe: Record types in C# ? Pin
Heath Stewart3-Feb-04 20:37
protectorHeath Stewart3-Feb-04 20:37 
GeneralRe: Record types in C# ? Pin
John Kuhn3-Feb-04 20:43
John Kuhn3-Feb-04 20:43 
GeneralRe: Record types in C# ? Pin
Andres Coder3-Feb-04 20:45
Andres Coder3-Feb-04 20:45 
GeneralRe: Record types in C# ? Pin
Heath Stewart4-Feb-04 3:29
protectorHeath Stewart4-Feb-04 3:29 
AnswerRe: Record types in C# ? Pin
Heath Stewart3-Feb-04 20:32
protectorHeath Stewart3-Feb-04 20:32 
I'm not familiar with Delphi, but it seems more like you have a class or struct here. The big difference between the two is that structs are allocated on the stack while classes are allocated on the heap. Classes are reference types so passing instances of classes as parameters passes a reference, where passing a struct passes a copy of the object (unless using the out or ref keywords).

In this case, you might be better of with a struct like:
public struct MyRecord
{
  public string Name;
  public int Age;
  public TMyProc Proc;
}
The only thing I'm not sure about is that last member. You say it's a "type" but it almost seems like a function pointer? In that case, you'll want to look up information on delegates in the .NET Framework SDK. If it's just any type, declare it as an object, which is the base class for ALL classes, structs, etc., in .NET.

An enum is more like a grouping of constants that provides type-safe access to such constants in .NET. For example, you could declare a bunch of constants like so:
public const int One = 1;
public const int Two = 2;
public const int Three = 3;
public void SomeMethod(int value)
{
  // Assuming non-contiquous values:
  if (value != 1 && value != 2 && value != 3)
    throw new ArgumentException("Invalid value.", "value");
  // Do stuff.
}
For SomeMethod, it can take any int so unless you want to hard-code and document the possible values, this isn't very type-safe. After all, any int could be supplied. If you only want this to accept certain values, then you should declare it like the following:
public enum MyEnum
{
  One = 1,
  Two, // increments to 2
  Three // increments to 3
}
public void SomeMethod(MyEnum value)
{
  if (!Enum.IsDefined(value.GetType(), value))
    throw new ArgumentException("Not defined.", "value");
  // Do stuff.
}
You still have to validate the param to be sure, but as you can see that's much easier and more flexible that checking it against hard-coded values. It also gives the caller some idea of what he or she can actually pass.

If you're new to the .NET Framework and the C# language (which is just one of many languages that target the Common Language Runtime, or CLR), you should definitely read the .NET Framework SDK to get an overview and review what's available in the base class library. It should've been installed with VS.NET and is also available online at http://msdn.microsoft.com/netframework[^].

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Record types in C# ? Pin
Andres Coder3-Feb-04 20:48
Andres Coder3-Feb-04 20:48 
Generalkernel process on c# Pin
laurentz_wei3-Feb-04 18:36
laurentz_wei3-Feb-04 18:36 
GeneralRe: kernel process on c# Pin
Heath Stewart3-Feb-04 20:21
protectorHeath Stewart3-Feb-04 20:21 
GeneralRe: kernel process on c# Pin
Mazdak3-Feb-04 20:24
Mazdak3-Feb-04 20:24 
GeneralOn Virtual And Override Pin
GetOn&GetGoing3-Feb-04 17:13
GetOn&GetGoing3-Feb-04 17:13 
GeneralRe: On Virtual And Override Pin
TigerNinja_3-Feb-04 17:38
TigerNinja_3-Feb-04 17:38 
GeneralRe: On Virtual And Override Pin
Heath Stewart3-Feb-04 20:18
protectorHeath Stewart3-Feb-04 20:18 
QuestionScrollBar bug? Pin
Meysam Mahfouzi3-Feb-04 16:58
Meysam Mahfouzi3-Feb-04 16:58 
Generalsome clarification on GDI+ vs. DIrectDraw Pin
SIDDHARTH_JAIN3-Feb-04 16:11
SIDDHARTH_JAIN3-Feb-04 16:11 
GeneralRe: some clarification on GDI+ vs. DIrectDraw Pin
Christian Graus3-Feb-04 17:44
protectorChristian Graus3-Feb-04 17:44 
GeneralRe: some clarification on GDI+ vs. DIrectDraw Pin
Michael Blome3-Feb-04 18:55
Michael Blome3-Feb-04 18:55 
GeneralRe: some clarification on GDI+ vs. DIrectDraw Pin
SIDDHARTH_JAIN4-Feb-04 11:36
SIDDHARTH_JAIN4-Feb-04 11:36 
GeneralPrepend to a file in C# Pin
pankajdaga3-Feb-04 13:27
pankajdaga3-Feb-04 13:27 
GeneralRe: Prepend to a file in C# Pin
John Kuhn3-Feb-04 17:29
John Kuhn3-Feb-04 17:29 
Generalsend an image in picturebox Pin
abido3-Feb-04 12:34
abido3-Feb-04 12:34 
GeneralRe: send an image in picturebox Pin
Heath Stewart3-Feb-04 20:13
protectorHeath Stewart3-Feb-04 20:13 
GeneralRe: send an image in picturebox Pin
John Kuhn3-Feb-04 21:02
John Kuhn3-Feb-04 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.