C SHARP interview questions part 18

C SHARP interview questions part 18

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Choose the exceptions generated by the GetResponseStream() method defined by WebRequest:

Correct Answer is : Interfaces

2. Which of these classes is used to create servers that listen to either local or remote client programs?

Correct Answer is : Public

3. Which of these methods gives the full URL of an URL object?

Correct Answer is : Array

4. What will be the output of the given code snippet? class Program{ static void Main(string[] args) { string[] strs = {"alpha", "beta", "gamma"}; var chrs = from str in strs let chrArray = str.ToCharArray() from ch in chrArray orderby ch select ch; Console.WriteLine("The individual characters in sorted order:"); foreach (char c in chrs) Console.Write(c + " "); Console.WriteLine(); Console.ReadLine(); }}

Correct Answer is : Both The IComparer interface is in System.Collections & It defines a method called Compare(), which compares the values of two objects

5. What will be the output of the given code snippet? class Program { static void Main(string[] args) { int[] nums = { 1, -2, 3, 0, -4, 5 }; var posNums = nums.Where(n => n > 0).Select(r => r*2).OrderByDescending(r=>r); Console.Write("The positive values in nums: "); foreach(int i in posNums) Console.Write(i + " "); Console.WriteLine(); Console.ReadLine(); } }

Correct Answer is : Both The IComparer is in System.Collections.Generic & It defines a generic form of Compare()

6. What will be the output of the given code snippet? class Program { static void Main(string[] args) { int[] nums = {3, 1, 2, 5, 4}; var ltAvg = from n in nums let x = nums.Average() where n < x select n; Console.WriteLine("The average is " + nums.Average()); Console.ReadLine(); } }

Correct Answer is : all of the mentioned

7. What will be the output of the given code snippet? class Program{ static void Main(string[] args) { Expression> IsFactorExp = (n, d) => (d != 0) ? (n % d) == 0 : false; Func IsFactor = IsFactorExp.Compile(); if (IsFactor(10, 5)) Console.WriteLine("5 is a factor of 10."); if (!IsFactor(343, 7)) Console.WriteLine("7 is not a factor of 10."); Console.ReadLine(); }}

Correct Answer is : The search begins at the index specified by index and is restricted to length elements. Returns the index of the first match.

8. Choose the namespace in which Expression trees are encapsulated:

Correct Answer is : TRUE

9. For the given set of codes, which query will work according to the set of code? class Program{ static void Main(string[] args) { int[] nums = { 1, -2, 3, 0, -4, 5 }; int len = /*_________________ */ Console.WriteLine("The number of positive values in nums: " + len); Console.ReadLine(); }}

Correct Answer is : Array elements:

10. For the given set of code, what does the output represent? class Program{ static void Main(string[] args) { int[] nums = { 1, -2, 3, 0, -4, 5 }; var posNums = from n in nums where n > 0 select n; int len = posNums.Count(); Console.WriteLine(len); Console.ReadLine(); }}

Correct Answer is : 5, 4, 3, 2, 1

11. Which of these methods of the class String is used to obtain length of String object?

Correct Answer is : 3

12. Which of these methods is an alternative to getChars() that stores the characters in an array of bytes?

Correct Answer is : Read(), ReadLine(), ReadKey()

13. Which of these methods can be used to convert all characters in a String into a character array?

Correct Answer is : Integer

14. What will be the output of the given code snippet? static void main(String args[]) { char chars[] = {'x', 'y', 'z'}; String s = new String(chars); Console.WriteLine(s); }

Correct Answer is : -1

15. Choose the effective stringBuilder method which helps in producing output for the given code? static void Main(string[] args) { StringBuilder s = new StringBuilder("object"); s./*______*/("Oriented Language"); Console.WriteLine(s); Console.ReadLine(); }Output : objectOriented Language

Correct Answer is : Console.In

16. What will be the output for the given code snippet? static void Main(string[] args) { string s = " i love you"; Console.WriteLine(s.IndexOf('l') + " " + s.lastIndexOf('o') + " " + s.IndexOf('e')); Console.ReadLine(); }

Correct Answer is : Console.Error

17. Which of these methods of class String is used to extract all the characters from a String object?

Correct Answer is : This will generate an exception

18. What will be the output of the given code snippet? static void Main(string[] args) { string c = "hello"; string c1 = c.Remove(1); Console.WriteLine(c1); Console.ReadLine(); }

Correct Answer is : Write & WriteLine

19. How is a string typically processed?

Correct Answer is : Runs successfully, ask for input and hence displays the result

20. What will be the output of the given code? class UnsafeCode { unsafe static void Main() { int m = 10; int *mptr = &m; int **ptr = &mptr; int n = 20; int *nptr = &n; int **prt = &nptr; m = **prt + *nptr; n = *mptr* **prt; Console.WriteLine(n + " " + m); Console.ReadLine(); } }

Correct Answer is : All of the mentioned

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon