Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Questions & Answers ? UrI Class
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
Explanation: None.
2. Which of these exceptions is thrown by the URL class’s constructors?
a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException
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
Explanation: By definition.
4. Which of these classes is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler
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
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
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?
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
int ch;
-
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://www.McGraw-Hill.com");
-
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
-
Stream istrm = resp.GetResponseStream();
-
for (int i = 1 ; ;i++)
-
{
-
ch = istrm.ReadByte();
-
if (ch == -1)
-
break;
-
Console.Write((char)ch);
-
if ((i % 400) == 0)
-
{
-
Console.Write("\nPress Enter.");
-
Console.ReadLine();
-
}
-
}
-
resp.Close();
-
}
-
}
a) html
b) text
c) html/text
d) text/html
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?
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
Uri obj = new Uri("https://www.sanfoundry.com/csharpmcq");
-
Console.WriteLine(obj.AbsoluteUri);
-
Console.ReadLine();
-
}
-
}
a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) https://www.sanfoundry.com/csharpmcq
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
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
Explanation: URL, URLDecoder and URLConnection – all these are used to access information stored in the URL.