What is generics in C#?

0 votes
Jul 6, 2019 in Others by Neha
• 330 points
205 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
104 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 6, 2019 in Others by Frankie
• 9,810 points
107 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
• 310 points
280 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,320 points
744 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,260 points
296 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 in Others by MD
• 65,200 points
282 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 in Others by MD
• 65,200 points
61 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 in Others by MD
• 65,200 points
53 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
82 views
+1 vote
1 answer

What is the difference between Dark Web and Deep Web?

The content that which you cannot find ...READ MORE

answered Feb 6, 2019 in Others by Priyaj
• 57,680 points
127 views