Practice 50 C# Data Types Programming Questions, TechnoVlogs

Practice 50 C# Data Types Programming Questions


Q1. Write a C# program to declare and initialize a variable of type int and print its value.  
  Input: int x = 10  
  Output: 10

Q2. Write a C# program to declare and initialize a variable of type double and print its value.  
  Input: double y = 20.5  
  Output: 20.5

Q3. Write a C# program to declare and initialize a variable of type char and print its value.  
  Input: char c = 'A'  
  Output: A

Q4. Write a C# program to declare and initialize a variable of type string and print its value.  
  Input: string name = "John"  
  Output: John

Q5. Write a C# program to declare and initialize a variable of type bool and print its value.  
  Input: bool isActive = true  
  Output: True

Q6. Write a C# program to declare a variable of type float, initialize it, and print its value.  
  Input: float price = 19.99f  
  Output: 19.99

Q7. Write a C# program to perform addition of two integers.  
  Input: a = 10, b = 20  
  Output: 30

Q8. Write a C# program to perform division of two integers and print the result as a float.  
  Input: a = 10, b = 3  
  Output: 3.333333

Q9. Write a C# program to convert an int to a double and print the result.  
  Input: int a = 10  
  Output: 10.0

Q10. Write a C# program to convert a double to an int and print the result.  
   Input: double b = 9.7  
   Output: 9

Q11. Write a C# program to declare an array of int type and print its elements.  
   Input: int[] arr = {1, 2, 3, 4, 5}  
   Output: 1 2 3 4 5

Q12. Write a C# program to declare an array of string type and print its elements.  
   Input: string[] colors = {"Red", "Green", "Blue"}  
   Output: Red Green Blue

Q13. Write a C# program to declare and initialize a long variable and print its value.  
   Input: long largeNum = 10000000000  
   Output: 10000000000

Q14. Write a C# program to check the size of int data type using sizeof.  
   Input: sizeof(int)  
   Output: 4

Q15. Write a C# program to declare and initialize a decimal variable and print its value.  
   Input: decimal amount = 99.99m  
   Output: 99.99

Q16. Write a C# program to declare and initialize a short variable and print its value.  
   Input: short smallNumber = 3000  
   Output: 3000

Q17. Write a C# program to swap two int variables without using a third variable.  
   Input: a = 10, b = 20  
   Output: a = 20, b = 10

Q18. Write a C# program to check if a bool value is true or false.  
   Input: bool isFinished = false  
   Output: False

Q19. Write a C# program to convert a string to int and print the result.  
   Input: string str = "123"  
   Output: 123

Q20. Write a C# program to check the size of double data type using sizeof.  
   Input: sizeof(double)  
   Output: 8

Q21. Write a C# program to declare a nullable int and print its value.  
   Input: int? x = null  
   Output: null

Q22. Write a C# program to assign null to a reference type variable and print it.  
   Input: string name = null  
   Output: null

Q23. Write a C# program to check the size of char data type using sizeof.  
   Input: sizeof(char)  
   Output: 2

Q24. Write a C# program to convert a char to string and print the result.  
   Input: char c = 'A'  
   Output: "A"

25. Write a C# program to print the largest value of int.  
   Input: int.MaxValue  
   Output: 2147483647

Q26. Write a C# program to print the smallest value of int.  
   Input: int.MinValue  
   Output: -2147483648

Q27. Write a C# program to print the largest value of double.  
   Input: double.MaxValue  
   Output: 1.7976931348623157E+308

Q28. Write a C# program to print the smallest value of double.  
   Input: double.MinValue  
   Output: -1.7976931348623157E+308

Q29. Write a C# program to declare a string and find its length.  
   Input: string name = "John"  
   Output: 4

Q30. Write a C# program to check whether a number is even or odd.  
   Input: num = 7  
   Output: Odd

Q31. Write a C# program to store and display a boolean value representing whether a number is positive.  
   Input: num = 10  
   Output: True

Q32. Write a C# program to check if a number is within a given range.  
   Input: num = 25, range = 10 to 30  
   Output: True

Q33. Write a C# program to declare and initialize an object type and print its value.  
   Input: object obj = "Hello World"  
   Output: Hello World

Q34. Write a C# program to perform implicit type conversion from int to double.  
   Input: int num = 10  
   Output: 10.0

Q35. Write a C# program to perform explicit type conversion from double to int.  
   Input: double value = 9.8  
   Output: 9

Q36. Write a C# program to declare a variable of DateTime type and print the current date.  
   Input: DateTime currentDate = DateTime.Now  
   Output: 2025-01-03 12:34:56 (depends on current time)

Q37. Write a C# program to convert a DateTime object to a string.  
   Input: DateTime currentDate = DateTime.Now  
   Output: "2025-01-03 12:34:56"

Q38. Write a C# program to demonstrate the difference between float and double.  
   Input: float f = 10.5f, double d = 10.5  
   Output: float: 10.5, double: 10.5

Q39. Write a C# program to find the ASCII value of a character.  
   Input: char c = 'A'  
   Output: 65

Q40. Write a C# program to check if a number is positive or negative.  
   Input: num = -5  
   Output: Negative

Q41. Write a C# program to assign and print a byte type variable.  
   Input: byte b = 255  
   Output: 255

Q42. Write a C# program to demonstrate casting from long to int.  
   Input: long l = 100000L  
   Output: 100000

Q43. Write a C# program to assign and print a uint type variable.  
   Input: uint u = 1000  
   Output: 1000

Q44. Write a C# program to demonstrate the DateTime data type and display the day of the week.  
   Input: DateTime date = new DateTime(2025, 1, 1)  
   Output: Wednesday

Q45. Write a C# program to convert an int to string.  
   Input: int number = 100  
   Output: "100"

Q46. Write a C# program to convert a string to char and print the character.  
   Input: string str = "A"  
   Output: A

Q47. Write a C# program to check if a double is equal to an int.  
   Input: double d = 10.0, int i = 10  
   Output: True

Q48. Write a C# program to assign and print a sbyte type variable.  
   Input: sbyte sb = -128  
   Output: -128

Q49. Write a C# program to demonstrate usage of object and print its type.  
   Input: object obj = 100  
   Output: System.Int32

Q50. Write a C# program to check if a float number is NaN (Not-a-Number).  
   Input: float value = float.NaN  
   Output: True

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!