Reputation: 45
Say I have this method:
public void UpdateEmployee ( String empFirst, String empLast, String empAddress,
String empType, String empPhoneNo, String empSalary, DateTime? dob, String empDepartment)
Is there a way not to repeat the type String all the time in the params?
Thanks
Upvotes: 0
Views: 92
Reputation: 264
There's no way to do exactly what you want (That I know of) in C# but you can try records:
public record Employee(string First, string Last, string Address, string Type);
That way you can write your code like this:
public void UpdateEmployee(Employee emp)
{
}
And allows you to re-use it!
There's also a way to create alias, but it's not recommended:
using s = System.String;
This way you can write your code like this:
public void UpdateEmployee(s empFirst, s empLast, s empAddress,
s empType, s empPhoneNo, s empSalary, DateTime? dob, s empDepartment)
{
}
Again, not recommended but good to know.
Upvotes: 5