content

Important Questions 1 - C# and Dotnet Tools

Same Questions as Assignment 1

Client side scripting languages are programming languages where the heavy processing happens client side, usually on the client application or on the web browser itself. Here are some client side scripting languages:

Crampete

Q2.What is “.NET Framework”?

The .NET Framework is a software framework created by Microsoft for development of Windows Apps.

This provides a set of libraries, tools, and a runtime environment to build apps with programming languages like C#, F#, Visual Basic, etc. With some effort, you can compile to various targets like Windows Desktop, Linux(x11/xWayland), Mac, web, mobile, and even build games using Godot(C# through mono), Unity(C#, Only for scripting),

Q3.What is “VB.NET”?

Visual Basic(previously known as VisualBasic.NET(VB.NET)) is an object oriented language for .NET, .NET Framewowrk and Mono

It is a successor to VB6 from .NET framework, and it supports OOP concepts like abstraction, encapsulation, inheritance, polymorphism. This means that everything in the language is an object.

It is not a case sensitive language, and is used to quickly develop a full object oriented program with full access to all libraries from the .NET Framework.

We can simplify this into these classifications of Web Technology:

Pros and Cons of Client-Side Scripting

Pros and Cons of Server-Side Scripting

There are five tokens in C#.

MSDotnet.co.in

Q7. Explain the OOP Concept in C#

Procedural programming is about writing procedures or methods that perform operations on the data, while object-oriented programming is about creating objects that contain both data and methods.

Object-oriented programming has several advantages over procedural programming:

Classes and objects are the two main aspects of object-oriented programming. Look at the following illustration to see the difference between class and objects: | Class | Objects | | — | — | | fruit | apple, banana, mango | | car | volvo, audi, toyota |

Everything in C# is associated with classes and objects, along with its attributes and methods.

In C#, there are 4 types of inheritance:

Program:

using System;

// Base class
class Animal {
    public void Speak() {
        Console.WriteLine("Animal speaks");
    }
}

// Derived class (Single Inheritance)
class Dog : Animal {
    public void Bark() {
        Console.WriteLine("Dog barks");
    }
}

// Derived class (Multi-level Inheritance)
class Puppy : Dog {
    public void Whine() {
        Console.WriteLine("Puppy whines");
    }
}

class Program {
    static void Main() {
        Puppy puppy = new Puppy();
        puppy.Speak(); // Inherited from Animal
        puppy.Bark();  // From Dog
        puppy.Whine(); // From Puppy
    }
}
graph TD;
    A[Animal] --> B[Dog]
    B --> C[Puppy]

GeeksForGeeks

Q9. Explain control structures with syntax and flow chart in C#

C# has the following conditional statements:

If statement:

Use the if statement to specify a block of C# code to be executed if a condition is True.

graph TD
    A([Start]) --> B{Condition}
    B -- Yes --> C[Execute Code Block]
    B -- No --> D([End])
    C --> D

Syntax:

if (condition) 
{
  // block of code to be executed if the condition is True
}

Example:

if (20 > 18) 
{
  Console.WriteLine("20 is greater than 18");
}

Else Statement:

Use the else statement to specify a block of code to be executed if the condition is False.

graph TD
    A([Start]) --> B{Condition}
    B -- Yes --> C[Execute Code Block]
    B -- No --> D[Execute Else Block]
    C --> E([End])
    D --> E

Syntax:

if (condition)
{
  // block of code to be executed if the condition is True
} 
else 
{
  // block of code to be executed if the condition is False
}

Example:

if (20 < 18) 
{
  Console.WriteLine("20 is less than 18");
} 
else 
{
  Console.WriteLine("20 is more than 18");
}

Ternary Operation:

Use the else if statement to specify a new condition if the first condition is False and fallback to else if that is also false.

graph TD
    A([Start]) --> B{Condition 1}
    B -- Yes --> C[Execute Code Block 1]
    B -- No --> D{Condition 2}
    D -- Yes --> E[Execute Code Block 2]
    D -- No --> F[Execute Else Block]
    C --> G([End])
    E --> G
    F --> G

Syntax:

if (condition1)
{
  // block of code to be executed if condition1 is True
} 
else if (condition2) 
{
  // block of code to be executed if the condition1 is false and condition2 is True
} 
else
{
  // block of code to be executed if the condition1 is false and condition2 is False
}

Example:

if (20 < 18) 
{
  Console.WriteLine("20 is less than 18");
} 
else if(30 < 20)
{
    Console.WriteLine("30 is less than 20");
}
else 
{
  Console.WriteLine("20 is more than 18");
}

Switch Statement:

Use the switch statement to select one of many code blocks to be executed.

graph TD
    A([Start]) --> B[Evaluate Expression]
    B --> C{Case 1}
    C -- Match --> D[Execute Case 1 Block]
    C -- No Match --> E{Case 2}
    E -- Match --> F[Execute Case 2 Block]
    E -- No Match --> G{Default Case}
    G -- Execute --> H[Execute Default Block]
    D --> I([End])
    F --> I
    H --> I

Syntax:

switch(expression) 
{
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
    break;
}

Example:

int day = 4;
switch (day) 
{
  case 1:
    Console.WriteLine("Monday");
    break;
  case 2:
    Console.WriteLine("Tuesday");
    break;
  case 3:
    Console.WriteLine("Wednesday");
    break;
  case 4:
    Console.WriteLine("Thursday");
    break;
  case 5:
    Console.WriteLine("Friday");
    break;
  case 6:
    Console.WriteLine("Saturday");
    break;
  case 7:
    Console.WriteLine("Sunday");
    break;
}

The break Keyword

The default Keyword

W3Schools

Q10.List the data types of C# programming

| Data Type | Size | Description | |–|–|–| | int| 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647| | long | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807| | float | 4 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits| | double | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits| | bool | 1 bit | Stores true or false values| | char | 2 bytes | Stores a single character/letter, surrounded by single quotes| | string | 2 bytes per character | Stores a sequence of characters, surrounded by double quotes|

GeeksForGeeks

Q11. Explain the different types of lists tags with examples

Lists (<ul>, <ol>, <li>): - Lists allow you to organize items in bullet points (<ul>) or numbered order (<ol>). Each item within a list is wrapped in <li> tags.

There are three types of lists in HTML

Shiksha

GeeksForGeeks

Q12.Explain types of operators with an example of each

Operators are tokens we use to perform operations with one, two or more operands. Types of Operators are:

GeeksForGeeks

Q13. What is the Difference between client side and server-side programming?

Server-side Programming :

It is the program that runs on server dealing with the generation of content of web page. 1) Querying the database 2) Operations over databases 3) Access/Write a file on server. 4) Interact with other servers. 5) Structure web applications. 6) Process user input. For example if user input is a text in search box, run a search algorithm on data stored on server and send the results.

Client-side Programming :

It is the program that runs on the client machine (browser) and deals with the user interface/display and any other processing that can happen on client machine like reading/writing cookies.

1) Interact with temporary storage 2) Make interactive web pages 3) Interact with local storage 4) Sending request for data to server 5) Send request to server 6) work as an interface between server and user

GeeksForGeeks

Q14.List the features of C# and explain them

Here are some features of C#: 1) Simple - C# is a simple language in the sense that it provides structured approach (to break the problem into parts), rich set of library functions, data types etc. 2) Modern Programming Language - C# programming is based upon the current trend and it is very powerful and simple for building scalable, interoperable and robust applications. 3) Object Oriented - C# is object oriented programming language. OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grow. 4) Type Safe - C# type safe code can only access the memory location that it has permission to execute. Therefore it improves a security of the program. 5) Interoperability - Interoperability process enables the C# programs to do almost anything that a native C++ application can do. 6) Scalable and Updateable - C# is automatic scalable and updateable programming language. For updating our application we delete the old files and update them with new ones. 7) Component Oriented - C# is component oriented programming language. It is the predominant software development methodology used to develop more robust and highly scalable applications. 8) Structured Programming Language - C# is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify. 9) Rich Library - C# provides a lot of inbuilt functions that makes the development fast. 10) Fast Speed - The compilation and execution time of C# language is fast.

JavaTPoint

Q15.List the features of VB.NET and explain them

Visual Basic is a high-level programming language with many features to develop a secure and robust application.

JavaTPoint

Q16. Write a basic structure of an HTML program

HTML documents are text files that contains structured code which tells browsers how to display a webpage.

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0" />
    <title>Structure of HTML Document</title>
</head>

<body>
    <!-- Main content of website -->
    <h1>BCA-Students</h1>
    <p>A one-stop place for solved questions</p>
</body>

</html>

As we can see, the document has the following elements:

GeeksForGeeks

Q17. List the different types of languages supported in .NET Framework

Popular .NET Programming Languages are:

Microsoft

Q18.Define try and catch block with an example program

When executing C# code, different errors can occur: coding errors made by the programmer, errors due to wrong input, or other unforeseeable things.

When an error occurs, C# will normally stop and generate an error message which means C# will throw an exception (throw an error).

Syntax:

try 
{
  //  Block of code to try
}
catch (Exception e)
{
  //  Block of code to handle errors
}

Program:

using System;
					
public class Program
{
	public static void Main()
	{
		try
		{
			int[] myNumbers = {1,2,3};
			Console.WriteLine(myNumbers[10]);
		}
	
		catch (Exception e)
		{
 			 Console.WriteLine(e.Message);
		}
	}
}

Output:

Index was outside the bounds of the array.

W3Schools

Q19.Explain different types of arrays in c#

There are three types of arrays in C#, which are

ScholarHat

Q20.Explain Mutable and Immutable strings in c#

Mutable and immutable are English words that mean “can change” and “cannot change” respectively.

That means the mutable types are those whose data members can be changed after the instance is created but Immutable types are those whose data members can not be changed after the instance is created.

When we change the value of mutable objects, value is changed in same memory. But in immutable type, the new memory is created and the modified value is stored in new memory.

String

Strings are immutable, which means we are creating new memory every time instead of working on existing memory.

StringBuilder

StringBuilder is a mutable type, that means we are using the same memory location and keep on appending/modifying the stuff to one instance. It will not create any further instances hence it will not decrease the performance of the application.

C-SharpCorner

Q21. Explain about Interfaces

An interface is a completely “abstract class”, which can only contain abstract methods and properties (with empty bodies)

It is considered good practice to start with the letter “I” at the beginning of an interface, as it makes it easier for yourself and others to remember that it is an interface and not a class.

Eg.

// interface
interface Animal 
{
  void animalSound(); // interface method (does not have a body)
  void run(); // interface method (does not have a body)
}

Full Example:

using System;

// Interface
interface IAnimal 
{
  void animalSound(); // interface method (does not have a body)
}

// Pig "implements" the IAnimal interface
class Pig : IAnimal 
{
  public void animalSound() 
  {
    // The body of animalSound() is provided here
    Console.WriteLine("The pig says: wee wee");
  }
}

class Program 
{
  static void Main(string[] args) 
  {
    Pig myPig = new Pig();  // Create a Pig object
    myPig.animalSound();
  }
}

W3Schools

Source: