C# Miscellaneous Types

Level : Advanced
Mentor: Shailendra Chauhan
Duration : 00:02:30

Anonymous Type:

Anonymous types in C# allow you to create objects with properties defined at compile-time without specifying a named class. They are often used for ad-hoc data structures.


var person = new { Name = "Mohan", Age = 30 };
Console.WriteLine($"Name: {person.Name}, Age: {person.Age}");

Var Type:

The 'var' keyword is used to implicitly declare variables, letting the compiler determine the data type based on the assigned value.


var number = 42;
Console.WriteLine($"Number is of type: {number.GetType()}");

Dynamic Type:

The 'dynamic' keyword allows you to create variables whose type is determined at runtime, providing flexibility but sacrificing compile-time type checking.


dynamic value = 10;
Console.WriteLine($"Dynamic value: {value}");
value = "Hello";
Console.WriteLine($"Dynamic value: {value}");


Tuples allow you to group multiple values of different types into a single data structure.


var personInfo = Tuple.Create("John", 30);
Console.WriteLine($"Name: {personInfo.Item1}, Age: {personInfo.Item2}");
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
Accept cookies & close this