- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get a specific field of the current type C#
To get a specific field of the current type in C#, the code is as follows −
Example
using System; using System.Reflection; public class Demo { public static void Main() { Type type = typeof(Subject); try { FieldInfo fieldInfo = type.GetField("SubName"); Console.WriteLine("FieldInfo = {0}", fieldInfo); } catch (ArgumentNullException e) { Console.Write("{0}", e.GetType(), e.Message); } } } public class Subject { public string SubName = "Science"; }
Output
This will produce the following output −
FieldInfo = System.String SubName
Example
Let us see another example −
using System; using System.Reflection; public class Demo { public static void Main() { Type type = typeof(Subject); try { FieldInfo fieldInfo = type.GetField(null); Console.WriteLine("FieldInfo = {0}", fieldInfo); } catch (ArgumentNullException e) { Console.Write("{0}", e.GetType(), e.Message); } } } public class Subject { public string SubName = "Science"; }
Output
This will produce the following output −
System.ArgumentNullException
- Related Articles
- Get a specific type nested within the current Type in C#
- Get a specific interface implemented or inherited by the current Type in C#
- Get the underlying type of the current enumeration type C#
- Get the fields of the current Type in C#
- Get the members of the current Type in C#
- Get the specified members of the current Type in C#?
- Get the types nested within the current Type C#
- Get the names of the members of the current enumeration type in C#
- Get the array of the values of the constants in the current enum type in C#
- Get the number of days between current date and date field?
- Get all the interfaces implemented or inherited by the current Type in C#
- Get count of array elements from a specific field in MongoDB documents?
- (a) What is a solenoid? Draw a sketch to show the magnetic field pattern produced by a current-carrying solenoid.(b) Name the type of magnet with which the magnetic field pattern of a current-carrying solenoid resembles. (c) What is the shape of field lines inside a current-carrying solenoid? What does the pattern of field lines inside a current-carrying solenoid indicate? (d) List three ways in which the magnetic field strength of a current-carrying solenoid can be increased? (e) What type of core should be put inside a current-carrying solenoid to make an electromagnet?
- Getting the type of the current instance in C#
- How to get current internet connection type in android?

Advertisements