What is generics in C#?

0 votes
Jul 6 in Others by Neha
• 330 points
49 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 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 in Others by Jobin
56 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 in Others by Frankie
• 9,810 points
35 views
+1 vote
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 in Others by Eric
• 260 points
85 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 in Others by ArchanaNagur
• 2,270 points
115 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 in Others by sunshine
• 1,240 points
69 views
0 votes
1 answer

What is the difference between hadoop and google analytics ?

I will try and answer this as ...READ MORE

answered Aug 21, 2018 in Others by Frankie
• 9,810 points
64 views
+5 votes
6 answers

what is artificial neural network?

Machine Learning is a field of computer ...READ MORE

answered Dec 16, 2018 in Others by Raghumishra
• 240 points
205 views
0 votes
1 answer
0 votes
1 answer

What is BASH in linux?

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

answered Mar 8 in Others by Tushar
28 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 in Others by Priyaj
• 56,940 points
71 views