C# unit1solvedQB
C# unit1solvedQB
A web browser is application software for accessing websites. When a user requests a web page from a
particular website, the browser retrieves its files from a web server and then displays the page on the user's
screen. Browsers are used on a range of devices, including desktops, laptops, tablets, and smartphones. Ex:
chrome,firefox,opera,IE
A web server is software and hardware that uses HTTP (Hypertext Transfer Protocol) and other protocols to
respond to client requests made over the World Wide Web. The main job of a web server is to display
website content through storing, processing and delivering webpages to users.
5. What is HTML?
HTML stands for Hypertext Markup Language. It is used to design the front-end portion of web pages using
a markup language. HTML is the combination of Hypertext and Markup language. Hypertext defines the
Page 1 of 31
link between the web pages. The markup language is used to define the text documentation within the tag
which defines the structure of web pages.
6. What is an HTML Element?
An HTML element is defined by a start tag, some content, and an end tag: Content goes here... The HTML
element is everything from the start tag to the end tag:
Page 2 of 31
9. Write a note on HTML DIV tag.
The div tag is known as Division tag. The div tag is used in HTML to make divisions of content in the
web page like (text, images, header, footer, navigation bar, etc). Div tag has both open(<div>) and closing
(</div>) tag and it is mandatory to close the tag.
The Div is the most usable tag in web development because it helps us to separate out data in the web
page and we can create a particular section for particular data or function in the web pages.
• Div tag is Block level tag
• It is a generic container tag
• It is used to the group of various tags of HTML so that sections can be created and style can be applied
to them.
As we know Div tag is block-level tag in this example div tag contain entire width. It will be displayed div
tag each time on a new line, not on the same line.
<html>
<head>
<title>gfg</title>
<style type=text/css>
div
{
color: white;
background-color: 009900;
margin: 2px;
font-size: 25px;
}
</style>
</head>
<body>
<div > div tag </div>
<div > div tag </div>
<div > div tag </div>
<div > div tag </div>
Page 3 of 31
</body>
</html>
Page 4 of 31
12. Write a note on HTML <img> Tag
Page 5 of 31
14. What is Client-Side Scripts ?
Client-side scripting is responsible for interaction within a web page. The client-side scripts are firstly
downloaded at the client-end and then interpreted and executed by the browser
The client-side scripting is browser-dependent. i.e., the client-side browser must be scripting enables in
order to run scripts.
Client-side scripting is used when the client-side interaction is used.
Here are some popular client-side scripting languages VBScript, JavaScript, Hypertext Processor(PHP).
15. What is Server-Side Scripts?
Server-side scripting is responsible for the completion or carrying out a task at the server-end and then
sending the result to the client-end.
Server-side scripting is mainly used when the information is sent to a server and to be processed at the
server-end. Some sample uses of server-scripting can be :
• Password Protection. • Browser Customization (sending information as per the requirements of client-end
browser) • Form Processing
Single line comments start with a double slash //. The compiler ignores everything after // to the end of the
line. For example,
Multi line comments start with /* and ends with */. Multi line comments can span over multiple lines. For
example,
Page 6 of 31
/*
*/
17. Define literals. List any two literal types used in C#.
The fixed values are called as Literal. Literal is a value that is used by the variables. Values can be either
an integer, float or string, etc.
// Here 100 is a constant/literal.
int x = 100;
Literals can be of the following types:
• Integer Literals
• Floating-point Literals
• Character Literals
• String Literals
• Null Literals
• Boolean Literals
Integer Literals
An integer literal can be a decimal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X
for hexadecimal, and there is no prefix id for decimal.
Here are some example of Integer Literals −
20 // int
30u // unsigned int
30l // long
Float Literals
A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can
represent floating point literals either in decimal form or exponential form.
Here are some examples of Float Literals −
2.64734
314159E-5F
18. What do you mean by Boxing/Unboxing?
Page 7 of 31
Unboxing: process of converting the object type back to the value type.
The process of converting reference type into the value type is known
as Unboxing.
Syntax:
condition ? statement 1 : statement 2
example
using System;
var result = x > y ? "x is greater than y" : "x is less than or equal to y";
Console.WriteLine(result);
}
}
Output
x is greater than y
Both “break” and “continue” are the ‘jump’ statements, that transfer control of the program to another part
of the program.
The main difference between break and continue is that break is used for immediate termination of loop.
On the other hand, ‘continue’ terminate the current iteration and resumes the control to the next iteration of
the loop.
Page 8 of 31
22. Distinguish between ref and out parameters.
• Private
• Protected
• Public
• Internal
24. What is variable size array ? Give example.
Variable length arrays are also known as runtime sized or variable sized arrays. The size of such arrays is
defined at run-time. Variably modified types include variable length arrays and pointers to variable length
arrays. Variably changed types must be declared at either block scope or function prototype scope.
Class is generally used in large programs. Struct are used in small programs.
Classes used new keyword for creating Struct can create an instance, with or without new
instances. keyword.
1) Bold Text
2) Italic Text
Page 11 of 31
5) Strike Text
Anything written within <strike>.......................</strike> element is displayed with strikethrough. It is a thin
line which cross the statement.
Example:
<p><strike>Text with strikethrough</strike>.</p>
Output:
Text with strikethrough
6) Superscript Text
If you put the content within <sup>..............</sup> element, is shown in superscript; means it is displayed
half a character's height above the other characters.
Example:
<p>x<sup>2</sup> +y<sup>2</sup></p>
Output:
X +y2
2
7)Subscript Text
If you put the content within <sub>..............</sub> element, is shown in subscript ; means it is displayed
half a character's height below the other characters.
Example:
<p>H<sub>2</sub> O</p>
Output:
H2O
2. Explain HTML Table Tags with an example.
HTML Table
HTML table tag is used to display data in tabular form (row * column). There can be many columns in a
row.
We can create a table to display data in tabular form, using <table> element, with the help of <tr> , <td>,
and <th> elements. In Each table, table row is defined by <tr> tag, table header is defined by <th>, and table
data is defined by <td> tags.
HTML tables are used to manage the layout of the page e.g. header section, navigation bar, body content,
footer section etc. But it is recommended to use div tag over table to manage the layout of the page .
HTML Table Tags
Tag Description
<table> It defines a table.
<tr> It defines a row in a table.
<th> It defines a header cell in a table.
Page 12 of 31
<td> It defines a cell in a table.
<caption> It defines the table caption.
<colgroup> It specifies a group of one or more columns in a table for formatting.
<col> It is used with <colgroup> element to specify column properties for each column.
<tbody> It is used to group the body content in a table.
<thead> It is used to group the header content in a table.
<tfooter> It is used to group the footer content in a table.
Example:
<!DOCTYPE>
<html>
<body>
<table>
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
<tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
<tr><td>James</td><td>William</td><td>80</td></tr>
<tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
<tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
</table>
</body>
</html>
Output:
In the ordered HTML lists, all the list items are marked with numbers by default. It is known as numbered
list also. The ordered list starts with <ol> tag and the list items start with <li> tag.
Page 13 of 31
<ol>
<li>Aries</li>
<li>Bingo</li>
<li>Leo</li>
<li>Oracle</li>
</ol>
Output:
1. Aries
2. Bingo
3. Leo
4. Oracle
In HTML Unordered list, all the list items are marked with bullets. It is also known as bulleted list also. The
Unordered list starts with <ul> tag and list items start with the <li> tag. Example:
<ul>
<li>Aries</li>
<li>Bingo</li>
<li>Leo</li>
<li>Oracle</li></ul>
Output:
o Aries
o Bingo
o Leo
o Oracle
Example:
Page 14 of 31
<dl>
<dt>Aries</dt>
<dd>-One of the 12 horoscope sign.</dd>
<dt>Bingo</dt>
<dd>-One of my evening snacks</dd>
<dt>Leo</dt>
<dd>-It is also an one of the 12 horoscope sign.</dd>
<dt>Oracle</dt>
<dd>-It is a
multinational
technology
corporation
Output:
Aries
-One of the 12 horoscope sign.
Bingo
-One of my evening snacks Leo
-It is also an one of the 12 horoscope sign.
Oracle
-It is a multinational technology corporation.
Page 15 of 31
Create Vertical frames:
Page 16 of 31
5.What are the Advantages and Disadvantages of Client Side Scripts.
Disadvantages
• Not all browsers support scripts, therefore, users might experience errors if no alternatives have been
provided.
• Different browsers and browser versions support scripts differently, thus more quality assurance testing
is required.
• More development time and effort might be required (if the scripts are not already available through
other resources).
• Developers have more control over the look and behaviour of their Web widgets; however, usability
problems can arise if a Web widget looks like a standard control but behaves differently or vice-versa.
Disadvantages:
• Many scripts and content management systems tools require databases in order to store dynamic data.
• It requires the scripting software to be installed on the server.
• The nature of dynamic scripts creates new security concerns, in some cases making it easier for hackers
to gain access to servers exploiting code flaws.
Page 17 of 31
7.Explain the Structure of C# Program .
The Documentation section consists of a set of comments giving the name of the program. Comments must
include:
• Why and what of classes
• How of algorithms
The Directive section will include all those namespaces that contain classes
required by the application. The directive section tells the compiler to look in the
namespace specified for these unresolved classes.
A C# program may contain multiple class definitions. Classes are the primary and
essential elements of a C# program. These classes are used to map the objects of
real-world problems.
Page 18 of 31
• C# Type System contains three data types: Value Types (int, char,
etc), ReferenceTypes (object) and Pointer Types.
Example :
Description :
• First declare a value type variable (num), which is integer type and
assigned it with value 23. Now create a references object type (obj) and
applied Explicit operation which results in num value type to be copied and
stored in object reference type object.
Unboxing: process of converting the object type back to the value type.
The process of converting reference type into the value type is known
as Unboxing.
Description :
with integer value 23. Now, create a reference object type (obj).The explicit
operation for boxing create an value type integer i and applied casting
method.
• When unboxing a value, ensure that value type is large enough to hold the
value of the object. Otherwise, the operation may result in runtime error.
When unboxing , we need to use explicit cast. This is because in the case of
unboxing an object could be casted to any type.
Page 19 of 31
9. What are the various forms of If Statements. Explain with example .
Simple IF Statement:
If(boolean expression)
else
False-block statement(s)
Statement-x;
Page 20 of 31
The Else If Ladder:
i)While:
Page 21 of 31
• The while loop loops through a block of code as long as a specified
condition is True:
• Syntax
• int i = 0;
• while (i < 5)
• {
• Console.WriteLine(i);
• i++;
• }
ii) Do……while :
• The do/while loop is a variant of the while loop. This loop will execute the
code block once, before checking if the condition is true, then it will repeat
the loop as long as the condition is true.
do {
while (condition);
The example below uses a do/while loop. The loop will always be executed at least
once, even if the condition is false, because the code block is executed before the
condition is tested:
int i = 0;
do
Console.WriteLine(i);
i++;
Page 22 of 31
while (i < 5);
iii)for:
Syntax:
For(initialization;test-condition; Increment/decrement)
Example:
For(int i=0;i<5;i++)
Console.WriteLine(i);
iv)For each:
The foreach statement is similar to the for statement. It enable us to Iterate the
elements in arrays.
Syntax:
Example:
int[] X={10,20,30,40};
Foreach(int I in X)
{
Page 23 of 31
Console.Write(“ “ +i);
• Syntax:
Method Body
Return type − A method may return a value. The return type is the data
type of the value the method returns. If the method is not returning any
values, then the return type is void.
Example :
return (x*y);
Page 24 of 31
12.What are method Parameters? Explain any Two Types.
When the method is invoked, the value of actual parameters is called to the formal
parameters.
• Output parameter .
Output parameters are similar to reference parameters, except that they transfer
data out of the method rather than into it.
It is similar to ref keyword, output parameter doesn’t create new memory location.
But the main difference between ref and out keyword is that ref needs that the
variable must be initialized before it passed to the method. But out parameter
doesn’t require the variables to be initialized before it passed to the method.
At times, while declaring a method, you are not sure of the number of arguments
passed as a parameter. C# param arrays (or parameter arrays) come into help at
such times.
Example:
static void display( params int[] X)
Page 25 of 31
{
foreach( int i in X)
Console.Write(i+ “”);
display(a);
display();
display(22,33);
Page 26 of 31
14. With example explain declaring and initializing one dimensional and two-
Create an Array
Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each
value.
string[] cars;
To insert values to it, we can use an array literal - place the values in a comma-separated list, inside curly
braces:
example
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
Console.WriteLine(cars[0]);
}
}
}
Output
Page 27 of 31
volvo
Here, x is a two-dimensional array with 2 elements. And, each element is also an array with 3 elements.
Note: The single comma [ , ] represents the array is 2 dimensional.
int[ , ] x = { { 1, 2 ,3}, { 3, 4, 5 } };
Here, x is a 2D array with two elements {1, 2, 3} and {3, 4, 5}. We can see that each element of the array is
also an array.
Example
using System;
namespace MultiDArray {
class Program {
static void Main(string[] args) {
//initializing 2D array
int[ , ] numbers = {{2, 3}, {4, 5}};
output
Page 28 of 31
In the above example, we have created a 2D array named numbers with rows {2, 3} and {4, 5}.
Here, we are using the index numbers to access elements of the 2D array.
• numbers[0, 0] - access the first element from the first row (2)
• numbers[1, 0] - access the first element from the second row (4)
using System;
namespace CsharpString {
class Test {
public static void Main(string [] args) {
Console.WriteLine(result);
Console.ReadLine();
}
}
}
Page 29 of 31
The Compare() method returns:
• 0 - if the strings are equal
• positive integer - if the first string comes after the second string in the alphabetical order
• negative integer - if the first string comes before the second string in the alphabetical order
Example
using System;
namespace CsharpString {
class Test {
public static void Main(string [] args) {
Console.WriteLine(result);
Console.ReadLine();
}
}
}
// Output: -1
ToUpper()
Example
using System;
namespace CsharpString {
class Test {
public static void Main(string [] args) {
Page 30 of 31
string str = "chocolate";
Console.WriteLine(result);
Console.ReadLine();
}
}
}
// Output: CHOCOLATE
Page 31 of 31