Posted By

sureshdasari on 11/13/18


Tagged

programming dotnet visualStudio abstract c# tutlane


Versions (?)

C# Abstract with Examples


 / Published in: C#
 

URL: https://www.tutlane.com/tutorial/csharp/csharp-abstract

In c#, abstract is a keyword which is used to define a classes and class members that are needs to be implemented or overridden in a derived class.

In c#, we can use abstract modifier with classes, methods,properties, events and indexers based on our requirements. The members which we defined as abstract or included in an abstract class those must be implemented by a classes that derive from an abstract class.

  1. using System;
  2.  
  3.  
  4. namespace Tutlane
  5.  
  6. {
  7.  
  8. abstract class Info
  9.  
  10. {
  11.  
  12. abstract public void GetDetails(string x, string y, int z);
  13.  
  14. }
  15.  
  16. class User : Info
  17.  
  18. {
  19.  
  20. public override void GetDetails(string a, string b, int c)
  21.  
  22. {
  23.  
  24. Console.WriteLine("Name: {0}", a);
  25.  
  26. Console.WriteLine("Location: {0}", b);
  27.  
  28. Console.WriteLine("Age: {0}", b);
  29.  
  30. }
  31.  
  32. }
  33.  
  34. class Program
  35.  
  36. {
  37.  
  38. static void Main(string[] args)
  39.  
  40. {
  41.  
  42. User u = new User();
  43.  
  44. Console.WriteLine("****Abstract Class Example****");
  45.  
  46. u.GetDetails("Suresh Dasari", "Hyderabad", 32);
  47.  
  48. Console.ReadLine();
  49.  
  50. }
  51.  
  52. }
  53.  
  54. }

Report this snippet  

You need to login to post a comment.