Q 1. What is NESTED Class ?
Ans. A class that can be declared within the scope of another class. These classes are considered within the scope of the enclosed class and are available within that class or scope.
Q 2. What do you mean by Projects ? Explain types of project in .NET ?
Typically, projects are files, for example, a .csproj file for a Visual C# project, that store references to source code files and resources like bitmap files. Projects let you organize, build, debug, and deploy source code, references to Web services and databases, and other resources.
Visual Studio comes with many project templates to create the necessary code and files to start developing applications. Details on few common project types are listed as
| Project Type | Description |
|---|---|
| Class library | Component library with no user interface |
| Console application | Command line application |
| Database project | SQL script storage |
| Device application | Windows application for a smart device |
| Empty project | Blank project |
| SQL Server project | Management of stored procedures and SQL Server objects |
| Web service | ASP.NET Web application with no user interface; technically, no longer a project type |
| Web site | ASP.NET Web application; technically, no longer a project type |
| Windows | Windows application with a user interface application |
| Windows service | Windows application with no user interface |
| WPF Browser Application | Windows Presentation Foundation browser application |
Visual Studio has templates pre-defined for most of programmer’s needs but custom project templates can also be developed by user for genearting some default content to use. Customizing involves the following steps
Ans. Data types determine the type of data that any variable can store. Variables belonging to different data types are allocated different amounts of space in the memory. There are various data types in VB.NET. They include:
Where,
Modifiers − specify the access level of the function; possible values are: Public, Private, Protected, Friend, Protected Friend and information regarding overloading, overriding, sharing, and shadowing.
FunctionName − indicates the name of the function
ParameterList − specifies the list of the parameters
ReturnType − specifies the data type of the variable the function returns
In Visual Basic, you can pass an argument to a procedure by value or by reference. This is known as the passing mechanism, and it determines whether the procedure can modify the programming element underlying the argument in the calling code. The procedure declaration determines the passing mechanism for each parameter by specifying the ByVal or ByRef keyword.
When passing an argument to a procedure, be aware of several different distinctions that interact with each other:
Whether the underlying programming element is modifiable or nonmodifiable
Whether the argument itself is modifiable or nonmodifiable
Whether the argument is being passed by value or by reference
Whether the argument data type is a value type or a reference type
You should choose the passing mechanism carefully for each argument.
Protection. In choosing between the two passing mechanisms, the most important criterion is the exposure of calling variables to change. The advantage of passing an argument ByRef is that the procedure can return a value to the calling code through that argument. The advantage of passing an argument ByVal is that it protects a variable from being changed by the procedure.
Performance. Although the passing mechanism can affect the performance of your code, the difference is usually insignificant. One exception to this is a value type passed ByVal. In this case, Visual Basic copies the entire data contents of the argument. Therefore, for a large value type such as a structure, it can be more efficient to pass it ByRef.
For reference types, only the pointer to the data is copied (four bytes on 32-bit platforms, eight bytes on 64-bit platforms). Therefore, you can pass arguments of type String or Object by value without harming performance.
The procedure declaration specifies the passing mechanism for each parameter. The calling code can't override a ByVal mechanism.
If a parameter is declared with ByRef, the calling code can force the mechanism to ByVal by enclosing the argument name in parentheses in the call. For more information, see How to: Force an Argument to Be Passed by Value.
The default in Visual Basic is to pass arguments by value.
If the calling code element underlying the argument is a nonmodifiable element, declare the corresponding parameter ByVal. No code can change the value of a nonmodifiable element.
If the underlying element is modifiable, but you do not want the procedure to be able to change its value, declare the parameter ByVal. Only the calling code can change the value of a modifiable element passed by value.
If the procedure has a genuine need to change the underlying element in the calling code, declare the corresponding parameter ByRef.
If the correct execution of the code depends on the procedure changing the underlying element in the calling code, declare the parameter ByRef. If you pass it by value, or if the calling code overrides the ByRef passing mechanism by enclosing the argument in parentheses, the procedure call might produce unexpected results.
A 1D array is a simple data structure that stores a collection of similar type data in a contiguous block of memory while the 2D array is a type of array that stores multiple data elements of the same type in matrix or table like format with a number of rows and columns. Thus, this is the main difference between 1D and 2D array.
A 1D array is also called single dimensional array while the 2D array is called multi-dimensional array.
Namespace and Assembly ?
A .Net Namespace provides the fundamental unit of logical code grouping while an assembly provides a fundamental unit of physical code grouping.
Namespace
Namespaces is a logical group of related classes that can be used by any other language targeting the Microsoft .Net framework.
Q 12.What is an assembly and its use? What is strong name in .NET assembly? What are the different types of assembly?
Ans. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. Assemblies take the form of executable (.exe) or dynamic link library (. dll) files, and are the building blocks of . NET applications.
A strong name consists of the assembly's identity—its simple text name, version number, and culture information (if provided)—plus a public key and a digital signature. It is generated from an assembly file using the corresponding private key.
The .NET Framework provides mainly three data providers: Microsoft SQL Server, OLEDB and ODBC.
| Parameter | Description | Default |
|---|---|---|
| Host | Specifies the host name - and optionally port - on which PostgreSQL is running. Multiple hosts may be specified, see the docs for more info. If the value begins with a slash, it is used as the directory for the Unix-domain socket (specifying a Port is still required). | Required |
| Port | The TCP port of the PostgreSQL server. | 5432 |
| Database | The PostgreSQL database to connect to. | Same as Username |
| Username | The username to connect with. Not required if using IntegratedSecurity. | PGUSER |
| Password | The password to connect with. Not required if using IntegratedSecurity. | PGPASSWORD |
| Passfile | Path to a PostgreSQL password file (PGPASSFILE), from which the password is taken. | PGPASSFILE |
Function, Sub, Operator, Get, Set) and a matching End declaration. All executable statements in Visual Basic must be within some procedure.Visual Basic uses several types of procedures:
Sub Procedures perform actions but do not return a value to the calling code.
Event-handling procedures are Sub procedures that execute in response to an event raised by user action or by an occurrence in a program.
Function Procedures return a value to the calling code. They can perform other actions before returning.
Some functions written in C# return a reference return value. Function callers can modify the return value, and this modification is reflected in the state of the called object. Starting with Visual Basic 2017, Visual Basic code can consume reference return values, although it cannot return a value by reference. For more information, see Reference return values.
Property Procedures return and assign values of properties on objects or modules.
Operator Procedures define the behavior of a standard operator when one or both of the operands is a newly-defined class or structure.
Generic Procedures in Visual Basic define one or more type parameters in addition to their normal parameters, so the calling code can pass specific data types each time it makes a call.
To tell the compiler that a certain constructor may not be used to implicitly cast an expression to its class type.
The explicit keyword is an optional decoration for constructors that take exactly one argument. It only applies to single-argument constructors since those are the only constructors that can be used in type casting.
The following are some of the commonly used properties of the ListBox control −
| Sr.No. | Property & Description |
|---|---|
| 1 | AllowSelection Gets a value indicating whether the ListBox currently enables selection of list items. |
| 2 | BorderStyle Gets or sets the type of border drawn around the list box. |
| 3 | ColumnWidth Gets of sets the width of columns in a multicolumn list box. |
| 4 | HorizontalExtent Gets or sets the horizontal scrolling area of a list box. |
| 5 | HorizontalScrollBar Gets or sets the value indicating whether a horizontal scrollbar is displayed in the list box. |
| 6 | ItemHeight Gets or sets the height of an item in the list box. |
| 7 | Items Gets the items of the list box. |
| 8 | MultiColumn Gets or sets a value indicating whether the list box supports multiple columns. |
| 9 | ScrollAlwaysVisible Gets or sets a value indicating whether the vertical scroll bar is shown at all times. |
| 10 | SelectedIndex Gets or sets the zero-based index of the currently selected item in a list box. |
| 11 | SelectedIndices Gets a collection that contains the zero-based indexes of all currently selected items in the list box. |
| 12 | SelectedItem Gets or sets the currently selected item in the list box. |
| 13 | SelectedItems Gets a collection containing the currently selected items in the list box. |
| 14 | SelectedValue Gets or sets the value of the member property specified by the ValueMember property. |
| 15 | SelectionMode Gets or sets the method in which items are selected in the list box. This property has values −
|
| 16 | Sorted Gets or sets a value indicating whether the items in the list box are sorted alphabetically. |
| 17 | Text Gets or searches for the text of the currently selected item in the list box. |
| 18 | TopIndex Gets or sets the index of the first visible item of a list box. |
The following are some of the commonly used events of the ListBox control −
| Sr.No. | Event & Description |
|---|---|
| 1 | Click Occurs when a list box is selected. |
| 2 | SelectedIndexChanged Occurs when the SelectedIndex property of a list box is changed. |
The following are some of the commonly used properties of the TreeView control −
| Sr.No. | Property & Description |
|---|---|
| 1 | BackColor Gets or sets the background color for the control. |
| 2 | BackgroundImage Gets or set the background image for the TreeView control. |
| 3 | BackgroundImageLayout Gets or sets the layout of the background image for the TreeView control. |
| 4 | BorderStyle Gets or sets the border style of the tree view control. |
| 5 | CheckBoxes Gets or sets a value indicating whether check boxes are displayed next to the tree nodes in the tree view control. |
| 6 | DataBindings Gets the data bindings for the control. |
| 7 | Font Gets or sets the font of the text displayed by the control. |
| 8 | FontHeight Gets or sets the height of the font of the control. |
| 9 | ForeColor The current foreground color for this control, which is the color the control uses to draw its text. |
| 10 | ItemHeight Gets or sets the height of each tree node in the tree view control. |
| 11 | Nodes Gets the collection of tree nodes that are assigned to the tree view control. |
| 12 | PathSeparator Gets or sets the delimiter string that the tree node path uses. |
| 13 | RightToLeftLayout Gets or sets a value that indicates whether the TreeView should be laid out from right-to-left. |
| 14 | Scrollable Gets or sets a value indicating whether the tree view control displays scroll bars when they are needed. |
| 15 | SelectedImageIndex Gets or sets the image list index value of the image that is displayed when a tree node is selected. |
| 16 | SelectedImageKey Gets or sets the key of the default image shown when a TreeNode is in a selected state. |
| 17 | SelectedNode Gets or sets the tree node that is currently selected in the tree view control. |
| 18 | ShowLines Gets or sets a value indicating whether lines are drawn between tree nodes in the tree view control. |
| 19 | ShowNodeToolTips Gets or sets a value indicating ToolTips are shown when the mouse pointer hovers over a TreeNode. |
| 20 | ShowPlusMinus Gets or sets a value indicating whether plus-sign (+) and minus-sign (-) buttons are displayed next to tree nodes that contain child tree nodes. |
| 21 | ShowRootLines Gets or sets a value indicating whether lines are drawn between the tree nodes that are at the root of the tree view. |
| 22 | Sorted Gets or sets a value indicating whether the tree nodes in the tree view are sorted. |
| 23 | StateImageList Gets or sets the image list that is used to indicate the state of the TreeView and its nodes. |
| 24 | Text Gets or sets the text of the TreeView. |
| 25 | TopNode Gets or sets the first fully-visible tree node in the tree view control. |
| 26 | TreeViewNodeSorter Gets or sets the implementation of IComparer to perform a custom sort of the TreeView nodes. |
| 27 | VisibleCount Gets the number of tree nodes that can be fully visible in the tree view control. |
The following are some of the commonly used events of the TreeView control −
| Sr.No. | Event & Description |
|---|---|
| 1 | AfterCheck Occurs after the tree node check box is checked. |
| 2 | AfterCollapse Occurs after the tree node is collapsed. |
| 3 | AfterExpand Occurs after the tree node is expanded. |
| 4 | AfterSelect Occurs after the tree node is selected. |
| 5 | BeforeCheck Occurs before the tree node check box is checked. |
| 6 | BeforeCollapse Occurs before the tree node is collapsed. |
| 7 | BeforeExpand Occurs before the tree node is expanded. |
| 8 | BeforeLabelEdit Occurs before the tree node label text is edited. |
| 9 | BeforeSelect Occurs before the tree node is selected. |
| 10 | ItemDrag Occurs when the user begins dragging a node. |
| 11 | NodeMouseClick Occurs when the user clicks a TreeNode with the mouse. |
| 12 | NodeMouseDoubleClick Occurs when the user double-clicks a TreeNode with the mouse. |
| 13 | NodeMouseHover Occurs when the mouse hovers over a TreeNode. |
| 14 | PaddingChanged Occurs when the value of the Padding property changes. |
| 15 | Paint Occurs when the TreeView is drawn. |
| 16 | RightToLeftLayoutChanged Occurs when the value of the RightToLeftLayout property changes. |
| 17 | TextChanged Occurs when the Text property changes. |
The following are some of the commonly used properties of the ScrollBar control −
| Sr.No. | Property & Description |
|---|---|
| 1 | AutoSize Gets or sets a value indicating whether the ScrollBar is automatically resized to fit its contents. |
| 2 | BackColor Gets or sets the background color for the control. |
| 3 | ForeColor Gets or sets the foreground color of the scroll bar control. |
| 4 | ImeMode Gets or sets the Input Method Editor (IME) mode supported by this control. |
| 5 | LargeChange Gets or sets a value to be added to or subtracted from the Value property when the scroll box is moved a large distance. |
| 6 | Maximum Gets or sets the upper limit of values of the scrollable range. |
| 7 | Minimum Gets or sets the lower limit of values of the scrollable range. |
| 8 | SmallChange Gets or sets the value to be added to or subtracted from the Value property when the scroll box is moved a small distance. |
| 9 | Value Gets or sets a numeric value that represents the current position of the scroll box on the scroll bar control. |
The following are some of the commonly used events of the ScrollBar control −
| Sr.No. | Event & Description |
|---|---|
| 1 | Click Occurs when the control is clicked. |
| 2 | DoubleClick Occurs when the user double-clicks the control. |
| 3 | Scroll Occurs when the control is moved. |
| 4 | ValueChanged Occurs when the Value property changes, either by handling the Scroll event or programmatically. |
The following are some of the commonly used properties of the PictureBox control −
| Sr.No. | Property & Description |
|---|---|
| 1 | AllowDrop Specifies whether the picture box accepts data that a user drags on it. |
| 2 | ErrorImage Gets or specifies an image to be displayed when an error occurs during the image-loading process or if the image load is cancelled. |
| 3 | Image Gets or sets the image that is displayed in the control. |
| 4 | ImageLocation Gets or sets the path or the URL for the image displayed in the control. |
| 5 | InitialImage Gets or sets the image displayed in the control when the main image is loaded. |
| 6 | SizeMode Determines the size of the image to be displayed in the control. This property takes its value from the PictureBoxSizeMode enumeration, which has values −
|
| 7 | TabIndex Gets or sets the tab index value. |
| 8 | TabStop Specifies whether the user will be able to focus on the picture box by using the TAB key. |
| 9 | Text Gets or sets the text for the picture box. |
| 10 | WaitOnLoad Specifies whether or not an image is loaded synchronously. |
The following are some of the commonly used events of the PictureBox control −
| Sr.No. | Event & Description |
|---|---|
| 1 | CausesValidationChanged Overrides the Control.CausesValidationChanged property. |
| 2 | Click Occurs when the control is clicked. |
| 3 | Enter Overrides the Control.Enter property. |
| 4 | FontChanged Occurs when the value of the Font property changes. |
| 5 | ForeColorChanged Occurs when the value of the ForeColor property changes. |
| 6 | KeyDown Occurs when a key is pressed when the control has focus. |
| 7 | KeyPress Occurs when a key is pressed when the control has focus. |
| 8 | KeyUp Occurs when a key is released when the control has focus. |
| 9 | Leave Occurs when input focus leaves the PictureBox. |
| 10 | LoadCompleted Occurs when the asynchronous image-load operation is completed, been canceled, or raised an exception. |
| 11 | LoadProgressChanged Occurs when the progress of an asynchronous image-loading operation has changed. |
| 12 | Resize Occurs when the control is resized. |
| 13 | RightToLeftChanged Occurs when the value of the RightToLeft property changes. |
| 14 | SizeChanged Occurs when the Size property value changes. |
| 15 | SizeModeChanged Occurs when SizeMode changes. |
| 16 | TabIndexChanged Occurs when the value of the TabIndex property changes. |
| 17 | TabStopChanged Occurs when the value of the TabStop property changes. |
| 18 | TextChanged Occurs when the value of the Text property changes. |
Now that we have created a combobox, let us demonstrate how to add items to it.
Double click the combobox control that you have added. You will be moved from the design tab to the tab with code.
To add an item to a combobox control, we use the Items property. Let us demonstrate this by adding two items to the combobox, Male and Female:
ComboBox1.Items.Add("Male")
ComboBox1.Items.Add("Female")
We can also choose to add items to the combobox at design time from the Properties window.
Program -
'Add items
ComboBox1.Items.Add(text)
'remove items
ComboBox1.Items.Remove(ComboBox1.SelectedItem)
Here are the steps:
Step 1) Open the design tab and click the combobox control.
Step 2) Move to the Properties window and view the Items option.
Step 3) Click the … located to the right of (Collection).
Step 4)You will see a new window. This is where you should add items to the combobox.
Step 5) Once done with typing the items, click the OK button.
Step 6) Click the Start button from the top toolbar and click the dropdown icon on the combobox.
The items were successfully added to the combobox control.
0 Comments