I'm looking for a equivalent to the Objective-c's Category for C# language.
Chronic liver disease in people with hepatitis C usually happens slowly, without any signs or symptoms, over several decades. Chronic hepatitis C virus infection is often not recognized until people are screened for blood donation or from an abnormal blood test found during a routine doctor's visit.
Hepatitis C virus (HCV) causes both acute and chronic infection. Acute HCV infections are usually asymptomatic and most do not lead to a life-threatening disease. Around 30% (15–45%) of infected persons spontaneously clear the virus within 6 months of infection without any treatment.
Hepatitis C is spread only through exposure to an infected person's blood. High-risk activities include: Sharing drug use equipment. Anything involved with injecting street drugs, from syringes, to needles, to tourniquets, can have small amounts of blood on it that can transmit hepatitis C.
Like the other antivirals, the side effects are mild. You might have a slight headache or bellyache, or you might feel tired. Glecaprevir and pibrentasvir (Mavyret): Three pills daily can treat all types of hep C. Side effects are mild and can include headache, fatigue, diarrhea, and nausea.
You can't add methods to a class, however you can use extension methods to achieve similar effects.
make a static class, with a static method. The static methods first argument is marked with "this" and the method is decorated to the classes with the type of the argument.
namespace ExtensionMethods
{
public static class MyExtensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' },
StringSplitOptions.RemoveEmptyEntries).Length;
}
}
}
This method will then be available on all instances of the type String. However you still have to have the extension class available through your usings.
The example is taken from Microsoft's own documention available here: http://msdn.microsoft.com/en-us/library/bb383977.aspx
The closest thing to Objective-C Categories in C# is Extension Methods.
Note that C# is a statically typed language and doesn't use dynamic dispatching like Objective-C does. That means that method resolution is performed at compile time and not at runtime, like you are used to in Objective-C.
Related resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With