What is generics in C

0 votes
Jul 7, 2019 in Others by Neha
• 330 points
842 views

1 answer to this question.

0 votes

Basically, generic is used when you need to write a class or a function which can work with any kind of data types. You can define classes and functions with a place holder. You can use it something like this:

using System; 
// < > to specify Parameter type 
public class example <T> { 
// private data members 
private T data; 
// using properties 
public T value 
{ 
// using accessors 
get
{ 
return this.data; 
} 
set
{ 
this.data = value; 
} 
} 
} 
// Driver class 
class Test { 
// Main method 
static void Main(string[] args) 
{ 
// instance of string type 
example<string> name = new example1<string>(); 
name.value = "anything"; 
// instance of float type 
example<float> version = new example<float>(); 
version.value = 5.0F; 
Console.WriteLine(name.value); 
// display 5 
Console.WriteLine(version.value); 
} 
}
answered Jul 8, 2019 by Sakshi

Related Questions In Others

0 votes
1 answer

What sort of testing is involved in functional testing?

The following types of testing are involved ...READ MORE

answered Feb 18, 2019 in Others by Jobin
445 views
0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
4,191 views
+4 votes
0 answers

What is the best way to pass CISSP Exam In first attempt?

Is CISSP Certification Worth. And What is ...READ MORE

Jun 25, 2019 in Others by Eric
• 320 points
1,015 views
0 votes
1 answer

What is use of Babel in Node.js ?

Node.js is a runtime environment  which let us ...READ MORE

answered Jul 2, 2019 in Others by ArchanaNagur
• 2,360 points
2,062 views
+1 vote
1 answer

what is the difference between error and stderr in Node.js?

Error is an object created by Node.js to handle ...READ MORE

answered Jul 4, 2019 in Others by sunshine
• 1,300 points
1,961 views
0 votes
1 answer

What is pubspec.yaml file in Flutter?

Hi@akhtar, It is the project's configuration file that ...READ MORE

answered Jul 20, 2020 in Others by MD
• 95,440 points
3,037 views
0 votes
1 answer

What is Hot Reload in Flutter?

Hi@akhtar, The hot reload feature allows you to ...READ MORE

answered Jul 20, 2020 in Others by MD
• 95,440 points
1,062 views
0 votes
1 answer

What is Material Design in Flutter?

Hi@akhtar, Material is a design system created by ...READ MORE

answered Jul 23, 2020 in Others by MD
• 95,440 points
601 views
0 votes
1 answer

What is BASH in linux?

BASH is short term for Bourne Again ...READ MORE

answered Mar 8, 2019 in Others by Tushar
528 views
0 votes
1 answer

What is CloudWatch in AWS?

Amazon CloudWatch is a monitoring tool provided ...READ MORE

answered Jan 22 in Others by Preetha
166 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP