Reputation: 75
I am new at c# and have been programming for many years in Delphi. I am stuck on the following problem and I hope someone can help me.
In Delphi you could declare a type:
type
TBtn = (btYes, btNo, btOK);
then create a procedure
procedure TfrmMain.Button(ABtn: TBtn);
begin
//Do something;
end;
and call the procedure like this
Button(btYes);
or
Button(btNo);
I want to do the same thing in C#
public Button (ABtn TBtn, string AString){
//Do Someting;
}
and call it
Button(btYes,"Hallo World");
How can I accomplish this?
Upvotes: 2
Views: 306
Reputation: 613612
In Delphi that is an enumerated type. The C# equivalent is an enum
.
Declare the type like this:
enum Btn {Yes, No, OK};
Declare the function like this:
public void Button(Btn btn, string str)
{
// Do Something;
}
And call the function like so:
Button(Btn.Yes, "Hallo World");
While you are still learning C#, I would recommend that you keep an introductory text close to hand.
Upvotes: 8