C# Questions & Answers – UrI Class

This section of our 1000+ C# MCQs focuses on Url class in C# Programming Language.

1. What does URL stand for?
a) Uniform Resource Locator
b) Uniform Resource Latch
c) Universal Resource Locator
d) Universal Resource Latch
View Answer

Answer: a
Explanation: None.

2. Which of these exceptions is thrown by the URL class’s constructors?
a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException
View Answer

Answer: c
Explanation: None.

3. What does the following form define?

advertisement
advertisement
  Protocol://HostName/FilePath?Query

a) Protocol specifies the protocol being used, such as HTTP
b) HostName identifies a specific server, such as mhprofessional.com or www.google.com
c) FilePath specifies the path to a specific file
d) All of the mentioned
View Answer

Answer: d
Explanation: By definition.
Note: Join free Sanfoundry classes at Telegram or Youtube

4. Which of these classes is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler
View Answer

Answer: c
Explanation: InetAddress class encapsulates both IP address and DNS, we can interact with this class by using the name of an IP host.

5. Which of these is a standard for communicating multimedia content over email?
a) http
b) https
c) Mime
d) httpd
View Answer

Answer: c
Explanation: MIME is an internet standard for communicating multimedia content over email. The HTTP protocol uses and extends the notion of MIME headers to pass attribute pairs between HTTP client and server.
advertisement

6. What does the following method specify?

   public static WebRequest Create(string requestUriString)

a) Creates a WebRequest object for the URI specified by the string passed by requestUriString
b) The object returned will implement the protocol specified by the prefix of the URI
c) The object will be an instance of the class that inherits WebRequest
d) All of the mentioned
View Answer

Answer: d
Explanation: Creates a WebRequest object for the URI specified by the string passed by requestUriString. The object returned will
implement the protocol specified by the prefix of the URI. Thus, the object will be an instance of a class that inherits WebRequest. A NotSupportedException is thrown if the requested protocol is not available. A UriFormatException is thrown if the URI format is invalid.
advertisement

7. What will be the output of the following C# code?

  1.   class Program
  2.   {
  3.       static void Main(string[] args)
  4.       {
  5.           int ch;
  6.           HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://www.McGraw-Hill.com");
  7.           HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
  8.           Stream istrm = resp.GetResponseStream();
  9.           for (int i = 1 ;  ;i++)
  10.           {
  11.               ch = istrm.ReadByte();
  12.               if (ch == -1) 
  13.               break;
  14.               Console.Write((char)ch);
  15.               if ((i % 400) == 0)
  16.               {
  17.                   Console.Write("\nPress Enter.");
  18.                   Console.ReadLine();
  19.               }
  20.           }
  21.           resp.Close();
  22.       }
  23.   }

a) html
b) text
c) html/text
d) text/html
View Answer

Answer: d
Explanation: The following program obtains the hypertext contained at a specific website. The program displays the hypertext on the screen.

8. What will be the output of the following C# code?

  1.  class Program
  2.  {
  3.      static void Main(string[] args) 
  4.      {
  5.          Uri obj = new Uri("https://www.sanfoundry.com/csharpmcq");
  6.          Console.WriteLine(obj.AbsoluteUri);
  7.          Console.ReadLine();
  8.      }
  9.  }

a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) https://www.sanfoundry.com/csharpmcq
View Answer

Answer: d
Explanation: AbsoluteUri is used to know the full URL of an URL object.
Output:

 https://www.sanfoundry.com/csharpmcq

9. Which of these data members of HttpResponse class is used to store the response from a http server?
a) status
b) address
c) statusResponse
d) statusCode
View Answer

Answer: d
Explanation: When we send a request to http server it responds with a status code. This status code is stored in statusCode and the textual equivalent is stored in reasonPhrase.

10. Which of these classes is used to access actual bits or content information of a URL?
a) URL
b) URLDecoder
c) URLConnection
d) All of the mentioned
View Answer

Answer: d
Explanation: URL, URLDecoder and URLConnection – all these are used to access information stored in the URL.

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all areas of C# language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.