c# polymorphism
C#
class Animal{
public virtual void animalSound() {
Console.WriteLine("The animal makes a sound");
}
}
class Pig: Animal {
public override void animalSound() {//override superclass method
Console.WriteLine("The pig says: wee wee");
}
}
class Dog: Animal {
public override void animalSound() {//override superclass method
Console.WriteLine("The dog says: bow wow");
}
}
static class main {
static void Main(){
//You can add all objects inherited from Animal to an Animal type list
Animal[] animals = new Animal[3]; //Creating the Animal List
animals[0] = new Animal(); //Add a new animal object to the list
animals[1] = new Dog(); //Add a new dog object to the list
animals[2] = new Pig(); //Add a pig object to the list
foreach (Animal a in animals){
a.animalSound(); //This statement prints the correct string no matter the class
}
}
}
Also in C#:
- Title
- unknown discriminator value mongodb
- Category
- C#
- Title
- letter at index of string c#
- Category
- C#
- Title
- dictionary update c#
- Category
- C#
- Title
- asp.net model display name
- Category
- C#
- Title
- unity print to console
- Category
- C#
- Title
- max of array C#
- Category
- C#
- Title
- enums c#
- Category
- C#
- Title
- uwp roaming data sample
- Category
- C#
- Title
- access dic by key c#
- Category
- C#
- Title
- unity persistent data
- Category
- C#
- Title
- How to search for a string from readline in c#
- Category
- C#
- Title
- unity onselect gizmos wireframe
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- onmouseclick unity
- Category
- C#
- Title
- c# scene manager
- Category
- C#
- Title
- c# keyboard enter
- Category
- C#
- Title
- 2d character controller unity
- Category
- C#
- Title
- unity how to make jump script
- Category
- C#
- Title
- check if network is available c#
- Category
- C#
- Title
- entity framework core
- Category
- C#
- Title
- c# round number
- Category
- C#
- Title
- no entity framework provider found for the ado.net provider with invariant name
- Category
- C#
- Title
- c# list remove item based on property duplicate
- Category
- C#
- Title
- how to change text to bold through script unity
- Category
- C#
- Title
- south african id number validation c#
- Category
- C#
- Title
- C# .NET Core linq Distinct
- Category
- C#
- Title
- set current date to textbox in asp.net
- Category
- C#
- Title
- how to set a gizmo color unity
- Category
- C#
- Title
- return random from enum
- Category
- C#
- Title
- unity how to add a bullet impact force
- Category
- C#
- Title
- c sharp int to string
- Category
- C#
- Title
- moq raise event
- Category
- C#
- Title
- gaussian blur unity sprite 2D
- Category
- C#
- Title
- csharp create array list
- Category
- C#
- Title
- c# check if string is only letters and numbers
- Category
- C#
- Title
- s3 upload base64 .net core
- Category
- C#
- Title
- .net identity seed users and roles
- Category
- C#
- Title
- how to stream video from vlc in c#
- Category
- C#
- Title
- c# edit element in list
- Category
- C#
- Title
- c# replace foreach with lambda
- Category
- C#
- Title
- c# exit for
- Category
- C#
- Title
- visual studio c# mark class deprecated
- Category
- C#
- Title
- unity deactive all object in list
- Category
- C#
- Title
- stop unity editor playing
- Category
- C#
- Title
- vector between two points unity
- Category
- C#
- Title
- getcomponent c#
- Category
- C#
- Title
- iphone
- Category
- C#
- Title
- Category
- C#
- Title
- unity c# set gameobject active
- Category
- C#
- Title
- oracle c# parameters wont work
- Category
- C#
- Title
- asp net identity add a unique fields to user
- Category
- C#
- Title
- instantiate offset unity
- Category
- C#
- Title
- winforms c# add data to datagridview with a button
- Category
- C#
- Title
- c# push numbers to array
- Category
- C#
- Title
- unity call function from another script
- Category
- C#
- Title
- c# tab character
- Category
- C#
- Title
- how to do cmd command c#
- Category
- C#
- Title
- c# web form compare dates
- Category
- C#
- Title
- get what week of the month c#
- Category
- C#
- Title
- c# access session in class
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- unity how to get data of play session time in a text file?
- Category
- C#
- Title
- how to make infinite loop in c#
- Category
- C#
- Title
- gersener waves
- Category
- C#
- Title
- c# join string array
- Category
- C#
- Title
- c# write variable in string
- Category
- C#
- Title
- c# display image
- Category
- C#
- Title
- convert array to list Unity C#
- Category
- C#
- Title
- how to import datagridview to datatable in c#
- Category
- C#
- Title
- vector3.lerp
- Category
- C#
- Title
- visual studio clear text script
- Category
- C#
- Title
- get specific object in list c#
- Category
- C#
- Title
- what does gameobject.find return
- Category
- C#
- Title
- c# half hour dropdown list
- Category
- C#
- Title
- C# webclient immitate browser
- Category
- C#
- Title
- c# map
- Category
- C#
- Title
- webclient c# example post
- Category
- C#
- Title
- for each textbox c#
- Category
- C#
- Title
- unity addforceatposition
- Category
- C#
- Title
- c# loop through list
- Category
- C#
- Title
- get string character by index c#
- Category
- C#
- Title
- c# string to byte array
- Category
- C#
- Title
- c sharp list of strings
- Category
- C#
- Title
- c# max sequence contains no elements
- Category
- C#
- Title
- c# download string url
- Category
- C#
- Title
- c# number suffixes
- Category
- C#
- Title
- entity framework update child records
- Category
- C#
- Title
- asp.net core redirecttoaction with parameters
- Category
- C#
- Title
- split string
- Category
- C#
- Title
- downlaod file and use C#
- Category
- C#
- Title
- c# param exception
- Category
- C#
- Title
- c# find comma in text and remove
- Category
- C#
- Title
- change partial view based on select asp.net core
- Category
- C#
- Title
- C# int to hex
- Category
- C#
- Title
- disable a component unity
- Category
- C#
- Title
- unity rotate object c#
- Category
- C#
- Title
- how to find the type of a object c#
- Category
- C#
- Title
- how to reload app.config file at runtime in c#
- Category
- C#
- Title
- or in C#
- Category
- C#
- Title
- c# implement a superclass in subclass
- Category
- C#