C# Questions & Answers ? UrI Class
Posted by Superadmin on August 24 2022 06:11:16

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

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

Answer: c
Explanation: None.

 

 

 

 

 

3. What does the following form define?

   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

Answer: d
Explanation: By definition.
 

 

 

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

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

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.

 

 

 

 

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

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.

 

 

 

 

 

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

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

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

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

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