Trending March 2024 # Learn The Types Of References In C# # Suggested April 2024 # Top 9 Popular

You are reading the article Learn The Types Of References In C# updated in March 2024 on the website Moimoishop.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 Learn The Types Of References In C#

Introduction to C# References

A memory location of a variable can be referenced by using a parameter called reference parameter in C# and they are different from parameters called value parameters in which the values are passed as parameters and a new memory location is created for these values whereas, in reference parameters, no memory location is allocated for these parameters as only the reference of these parameters are passed and the reference parameters can be declared by using the keyword ref.

Start Your Free Software Development Course

The syntax to declare the reference parameter in C# is as follows:

return type Method name(ref arg1, ref arg2) Declare local variables, for example a, b Calling the method, Method name(ref a, ref b)

The above syntax represents declaring reference parameters in C#. The reference parameters can be declared by using the keyword ref and they can be accessed by using the keyword ref.

Working of Reference Parameters in C#

Consider the following program which consists of two methods add and subtract. The add method accepts the parameter passed by value and the subtract method accepts the parameter passed as a reference. Initially, two variables are declared and initialized with two values. Then add method is called by passing the value as the parameter. There is no change in the value even though the method is supposed to perform the operation on the value passed as a parameter because this passes by value. The next subtract method is called to which the reference parameter is passed. The operation defined in the subtract method is performed on the value passed as a reference and it is updated.

Code:

using System; namespace refer { public class check { public void Main(string[] args) { int a = 15, b = 20; Console.WriteLine("value of a before changing is {0}", a); Console.WriteLine("value of b before changing is {0}", b); Console.WriteLine(); add(a); Console.WriteLine("After calling the add function"+ " value of a is {0}", a); subtract(ref b); Console.WriteLine("Value of b after "+ "subtration operation is {0}", b); } public static void add(int a) { a += 5; } public static void subtract(ref int b) { b -= 5; } } }

Output:

Types of References in C#

Here are the following Types of References in C#

1. Class

Class is one of the C# reference types and they can be declared using the keyword class. The syntax to declare a class in C# is shown below:

Class classname { }

The class supports inheritance. That is a class can inherit the implementation of the base class. Classes can be either public, private, protected. The following program demonstrates the creation of the class.

using System; namespace check { class children { private int height; private string names; public children() { names = "nobody"; } public children(string names, int height) { this.names = names; this.height = height; } public void Print() { Console.WriteLine("{0} is {1} inches tall.", names, height); } } class Test { static void Main() { children child1 = new children("Shobha", 5); children child2 = new children("Ravi", 6); children child3 = new children(); Console.Write("The first child: "); child1.Print(); Console.Write("The second child: "); child2.Print(); Console.Write("The third child: "); child3.Print(); } } }

Output:

2. Interface

A contract is defined using an interface. The members of any class have a definite implementation provided by the interface. The following program demonstrates the creation and implementation of the interface.

Code:

using System; interface Point { int A { get; set; } int B { get; set; } double Dist { get; } } class Pointed : Point { public Pointed(int a, int b) { A = a; B = b; } public int A { get; set; } public int B { get; set; } Math.Sqrt(A * A + B * B); } class Maincl { static void PrintPointed(Point r) { Console.WriteLine("a={0}, b={1}", r.A, r.B); } static void Main() { Point r = new Pointed(2, 3); Console.Write("the points are: "); PrintPointed(r); } }

Output:

3. Delegate

The declaration of a delegate type is like the declaration of a method. It returns a value and it can take any number of arguments of any type as parameters. It is basically used in the encapsulation of methods acting as a pointer to a function. A delegate can be declared using the delegate keyword. The syntax to declare the delegate is as follows:

Consider the below program demonstrating the creation of delegates

Code:

using System; class Program { public delegate void Printdel(int values); static void Main(string[] args) { Printdel print = PrintNum; print(100); print(20); print = PrintMon; print(10); print(20); } public static void PrintNum(int number) { Console.WriteLine("The Number is: {0,-12:N0}",number); } public static void PrintMon(int mon) { Console.WriteLine("The Money is: {0:C}", mon); } }

Output:

Conclusion

In this tutorial, we understand the concept of References in C# through definition and then understand the syntax and types of references in C# through example programs.

Recommended Articles

This is a guide to C# References. Here we discuss the Types of References in C# along with the syntax and the working of the reference parameter. You may also have a look at the following articles to learn more –

You're reading Learn The Types Of References In C#

Data Types In C#: Double, Integer, Float, Char

What are Data Types in C#?

The C# language comes with a set of Basic data types. These data types are used to build values which are used within an application. Let’s explore the basic data types available in C#. For each example, we will modify just the main function in our chúng tôi file.

1) Integer

An Integer data types are used to work with numbers. In this case, the numbers are whole numbers like 10, 20 or 30. In C#, the datatype is denoted by the Int32 keyword. Below is an example of how this datatype can be used. In our example, we will define an Int32 variable called num. We will then assign an Integer value to the variable and then display it accordingly.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class Program { static void Main(string[] args) { Int32 num=30; Console.Write(num); Console.ReadKey(); } } } Code Explanation:-

The Int32 data type is specified to declare an Integer variable called num. The variable is then assigned a value of 30.

Finally the console.write function is used to display the number to the console.

If the above code is entered properly and the program is executed successfully, following output will be displayed.

Output:

From the output, you can clearly see that the Integer variable called num was displayed in the console

2) Double

A double data type is used to work with decimals. In this case, the numbers are whole numbers like 10.11, 20.22 or 30.33. In C#, the datatype is denoted by the keyword “Double“. Below is an example of this datatype.

In our example, we will define a double variable called num. We will then assign a Double value to the variable and then display it accordingly.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class Program { static void Main(string[] args) { double num=30.33; Console.Write(num); Console.ReadKey(); } } } Code Explanation:-

The double data type is specified to declare a double type variable called num. The variable is then assigned a value of 30.33.

Finally the console.write function is used to display the number to the console.

If the above code is entered properly and the program is executed successfully, following output will be displayed.

Output:

From the output, you can clearly see that the double variable called num was displayed in the console

3) Boolean

A boolean data type is used to work with Boolean values of true and false. In C#, the datatype is denoted by the Boolean keyword. Below is an example of this datatype can be used.

In our example, we will define a Boolean variable called ‘status.’ We will then assign a boolean value to the variable and then display it accordingly.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class Program { static void Main(string[] args) { Boolean status=true; Console.Write(status); Console.ReadKey(); } } } Code Explanation:-

The boolean data type is specified to declare a Boolean variable called ‘status.’ The variable is then assigned a value of true/false.

Finally the console.write function is used to display the Boolean value to the console.

If the above code is entered properly and the program is executed successfully, the output will be displayed.

Output:

From the output, you can clearly see that the Boolean variable which equals true was displayed in the console

4) String

A String data type is used to work with String values. In C#, the datatype is denoted by the keyword ‘String’. Below is an example of this datatype.

In our example, we will define a String variable called ‘message.’ We will then assign a String value to the variable and then display it accordingly.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class program { static void Main(string[] args) { String message="Hello"; Console.Write(message); Console.ReadKey(); } } } Code Explanation:-

The String data type is specified to declare a string variable called message. The variable is then assigned a value of “Hello”.

Finally, the console.write function is used to display the string value to the console.

If the above code is entered properly and the program is executed successfully, the output will be displayed.

Output:

From the output, you can clearly see that the String variable called message was displayed in the console

Learn The Working Of Unhide In Sketchup

Introduction to SketchUp Unhide How Unhide works in SketchUp?

You can unhide objects in this software by using menus of the menu bar and some other options so let me tell you how you can do this during your work.

Start Your Free Design Course

3D animation, modelling, simulation, game development & others

I have downloaded this chair’s model from the 3D warehouse of SketchUp to explain this topic. You can learn and practices this on your own designed model.

Once I will choose this option, it will hide our selected chair. I will do the same with some other chairs.

And you can see it will unhide the entire hidden object, but this option (Last) is used to unhide the last unhide object. In the current case, it unhides all hidden objects because we have been hiding all chairs one by one in sequence.

Now let us understand this option in another way through which it will only unhide the last hidden object. I will hide this selected chair again and then create an object like this by using push/pull and rectangle tools.

I will add one block to this object also.

It will unhide only the last hidden chair. So I think you got it that if we hide any component then do other design work, then it will only unhide the last hidden object.

I will hide this drawn object too in the same way.

Now once again, go to Unhide option of the Edit menu and this time choose the All sub-option of Unhide option.

And it will show you a wireframe view of all hidden objects of your working model like this. I have been hidden these chairs only, so it is showing them only.

Now I will select this first chair which is in wireframe view, and choose Selected sub-option from the Unhide option.

And it will unhide only this chair. So by this way, you can unhide only your desired object or component during working on any project.

Here in the dialog box of Model info, choose the Components option from the shown list.

If you select other components, then the first select object will become disappear like this.

Here in the dialog box of Preferences, choose the Shortcuts option from the shown list and select the ‘Hide rest of object’ option in the list of Functions tab. Then go to Add Shortcut box and assign your desired key with a combination of the Ctrl key of the keyboard. Once you assign a key to it, if that combination of keys is already assigned to another command, then it will show you a message that it is already assigned. So choose that one that is not allotted to another command.

Conclusion

These were some important aspects of Unhide feature of SketchUp, and you can use it for having smooth working ability during creating a 3D model. You can go with any of the above-discussed ways according to your work requirement. You can also assign a shortcut key to ‘hide other objects’ as per your choice for speeding up your working skill in SketchUp.

Recommended Articles

This is a guide to SketchUp Unhide. Here we discuss the working of Unhide in SketchUp by using few options through which you can do the process of unhiding objects. You may also have a look at the following articles to learn more –

Types Of Error In Php

Introduction to Error in PHP

The event of the occurrence of deviation of the result from the accurate result is termed as an Error. In PHP, error can be generated because of the usage of an incorrect format of coding or implementation of non-feasible functionality. Based on the root cause and level of severity, errors in PHP are categorized in 4 types, such as:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax error (Parse error)

Warning Error

Notice error

Fatal error

Types of Errors in PHP

Lets discuss the Types of Error in PHP.

1. Syntax Error (Parse Error)

In PHP, the scripting needs to follow standard grammar to develop an executable code. When the written code syntax gets deviated from the standard, syntax error takes place. It is also called as parse error. This error gets checked in the compilation stage itself and execution of the code gets stopped. It does not allow the execution unless the error is not fixed and compilation is completed without any syntax flaw. The error constant that is used to represent compile time parse (syntax) error: E_PARSE

Example:

The below code snippet is developed to assign values to PHP variables and display the stores values on the output window.

<?php $Correct_Var = "Writing a code to demonstrate Syntax(Parse Error)"; Incorrect_Var = "The '$' symbol is missing for variable y!!!"; echo $Correct_Var; echo Incorrect_Var;

Output:

PHP compiler understand existence of any variable when a string is associated with $ symbol. In the above code, definition of variable Incorrect_Var does not satisfy the grammar, hence the compiler throws syntax error for the code and execution is interrupted.

2. Warning Error

This error arises when the PHP script is trying to process any invalid information such as trying to perform a file operation on a file which does not exist or try to call a function with number of input values i.e. different from number of arguments present in the calling function definition. These are serious errors but does not stop the execution of the program and ends in exhibiting unexpected result. The error constant that is used to represent run time warning without terminating script execution: E_WARNING

Example:

The below code snippet is written to call another script file within the current programming.

<?php echo "Beginning of program execution"; $Correct_Var = "Writing a code to demonstrate Warning Error"; echo $Correct_Var; include ("MissingScript.php"); echo "Ending of program execution";

Output:

According to the programming, compiler successfully compiled to code and starts execution. The execution continues sequentially. For the command include (“MissingScript.php”), it is looking for the script in the default path …/usr/share/php and does not found any script with the given name. Thus it ends in resulting the warning message for that specific command and execution the rest of the code as designed.

3. Notice Error

Example:

<?php echo "Beginning of program execution"; $Correct_Var = "Writing a code to demonstrate Notice Error"; echo $InCorrect_Var; echo "Ending of program execution";

Output:

The compiler does not recognize the variable $InCorrect_Var as it is not defined in the code. Hence it throws the Notice error.

4. Fatal Error

A compile time error that is encountered due to any invalid command such as missing of function definition for a calling function, is coined as fatal error. Severity level of this type of error is critical and hence it does not let the execution to be proceed and throw fatal error message as output. The error constant that is used to represent the fatal error which triggers script termination: E_ERROR

Example:

The below code snippet is designed to call demonstrate application of function in PHP scripting.

<?php echo "Beginning of program execution"; $Correct_Var = "Writing a code to demonstrate Fatal Error"; echo $Correct_Var; UndefinedFunction();//Calling a function which is not defined in the script echo "Ending of program execution";

Output:

Additional Note

1. Error handling is easy in PHP. If any developer does not have access to the complete code for any application, it is recommended to use error handling functions in possible scenarios.

2. In order to avoid new error in the PHP programming, developer is expected to follow proper coding guidelines and stays alert towards probabilities of various types of errors, warnings and notices.

3. It is recommended not to allow any error or warning or notice to be displayed to the user. Hence the best practice for any safe PHP programming to ensure the required configuration to be available in chúng tôi file.

The desired value for the below variables are:

error_reporting as ' E_ALL' display_errors as 'Off' log_errors as 'On'

The below code can be included in any PHP script to configure the desired values in the chúng tôi file:

error_reporting(E_ALL); ini_set('display_errors','0'); ini_set('log_errors','1');

This function needs to be designed with some specific guidelines as follows:

Function should be capable of handling minimum of two input parameters: error message and error level and maximum of 5 input parameters by including the optional parameters such as line number, file and error context.

Recommended Articles

This is a guide to Types of Error in PHP. Here we discuss the introduction and 4 types of errors in PHP along with different examples and code implementation. you may also have a look at the following articles to learn more –

How To Get The Remaining Elements Of The Tuple In C#?

To get the remaining elements of the Tuple, the Rest property is used. The code is as follows −

Example

Live Demo

using System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 1st = "+tuple1.Item1);       Console.WriteLine("Tuple2 Item 1st = "+tuple2.Item1);       Console.WriteLine("Tuple1 Item 2nd = "+tuple1.Item2);       Console.WriteLine("Tuple2 Item 2nd = "+tuple2.Item2);       Console.WriteLine("Tuple1 Item 4th = "+tuple1.Item4);       Console.WriteLine("Tuple2 Item 4th = "+tuple2.Item4);       Console.WriteLine("Tuple1 Item 5th = "+tuple1.Item5);       Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item5);       Console.WriteLine("Tuple1 Item 6th = "+tuple1.Item6);       Console.WriteLine("Tuple2 Item 6th = "+tuple2.Item6);       Console.WriteLine("Tuple1 Item 7th = "+tuple1.Item7);       Console.WriteLine("Tuple2 Item 7th = "+tuple2.Item7);       Console.WriteLine("Tuple1 rest value = "+tuple1.Rest);       Console.WriteLine("Tuple2 rest value = "+tuple2.Rest);    } } Output

This will produce the following output −

Is Tuple1 equal to Tuple2? = True HashCode of Tuple1 = 3247155 HashCode of Tuple2 = 3247155 Tuple1 Item 1st = 75 Tuple2 Item 1st = 75 Tuple1 Item 2nd = 200 Tuple2 Item 2nd = 200 Tuple1 Item 4th = 700 Tuple2 Item 4th = 700 Tuple1 Item 5th = 100 Tuple2 Item 5th = 100 Tuple1 Item 6th = 1200 Tuple2 Item 6th = 1200 Tuple1 Item 7th = 1500 Tuple2 Item 7th = 1500 Tuple1 rest value = (2000) Tuple2 rest value = (2000) Example

Let us now see another example −

 Live Demo

using System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, Tuple.Create("AB", 2000, "CD"));       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, Tuple.Create(2500, 3500, 4000, "XY"));       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 1st = "+tuple1.Item1);       Console.WriteLine("Tuple2 Item 1st = "+tuple2.Item1);       Console.WriteLine("Tuple1 Item 2nd = "+tuple1.Item2);       Console.WriteLine("Tuple2 Item 2nd = "+tuple2.Item2);       Console.WriteLine("Tuple1 Item 4th = "+tuple1.Item4);       Console.WriteLine("Tuple2 Item 4th = "+tuple2.Item4);       Console.WriteLine("Tuple1 Item 5th = "+tuple1.Item5);       Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item5);       Console.WriteLine("Tuple1 Item 6th = "+tuple1.Item6);       Console.WriteLine("Tuple2 Item 6th = "+tuple2.Item6);       Console.WriteLine("Tuple1 Item 7th = "+tuple1.Item7);       Console.WriteLine("Tuple2 Item 7th = "+tuple2.Item7);       Console.WriteLine("Tuple1 rest value = "+tuple1.Rest);       Console.WriteLine("Tuple2 rest value = "+tuple2.Rest);    } } Output

This will produce the following output −

Is Tuple1 equal to Tuple2? = False HashCode of Tuple1 = -1121878415 HashCode of Tuple2 = -835095725 Tuple1 Item 1st = 75 Tuple2 Item 1st = 75 Tuple1 Item 2nd = 200 Tuple2 Item 2nd = 200 Tuple1 Item 4th = 700 Tuple2 Item 4th = 700 Tuple1 Item 5th = 100 Tuple2 Item 5th = 100 Tuple1 Item 6th = 1200 Tuple2 Item 6th = 1200 Tuple1 Item 7th = 1500 Tuple2 Item 7th = 1500 Tuple1 rest value = ((AB, 2000, CD)) Tuple2 rest value = ((2500, 3500, 4000, XY))

Learn The Examples Of The Load() Method

Introduction to jQuery load()

The load() method of jQuery is used to get data from the server and place the HTML or text response in an element in the DOM. So, basically, it is a combination of two conventional methods of most scripting languages – the global get method and the respective methods to get the element in DOM and set their contents. If the element selector does not correspond to any element in the DOM, the load method is not called.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

NOTE: Prior to jQuery v3.0, there was an event handler in jQuery by the name of the load. Whether the event handler would be invoked or the method was determined at run time based on the number of arguments passed. Post jQuery v3.0, the event handler has been deprecated, and we now only have the load() method to get data from the server and modify the contents of DOM elements with the response.

Syntax of load() Method

The syntax of the load() method has three variants based on the number of optional parameters passed to the method.

The basic and the most elementary syntax is as follows:

Here data is sent along with the request object to the server. This is useful in cases when your server expects some data or some parameters along with the request object. A simple example would be the id of the person whose details are requested from the server.

Then there is the third syntax which includes a callback function:

Here complete is the callback function, which is called when the request to the server is completed. A request to the server is considered complete post the receipt of the response and the DOM manipulation of the element. A very important point to note here is that this callback function is called once for every element in the selector.

NOTE: If data is sent along with the request, the POST method is used by jQuery. If not, the GET method is assumed.

How does the load Method Work?

Let’s see behind the scenes of the load method.

Step 1 – It begins with finding the element in the DOM.

Step 2 – If the element is found, the next step is to send an AJAX request to the server at the specified url. An AJAX is an Asynchronous JavaScript and XML call. Since they are asynchronous, they do need a page refresh.

Step 3 – Once the response is received from the server, the next step is to insert the DOM element’s response. jQuery uses the browser’s innerHTML property to manipulate the contents of the element.

Step 4 – Now is the time to execute any callback functions, if present.

Examples of jQuery load()

Let us look at some of the examples of the load() method.

NOTE: Throughout the examples in this article, we would be using the browsers’ developer console. Simply open the browser developer tools (Ctrl/Cmd + Shift + C) and go to the Console tab in the developer tools window.

It looks like this in Chrome:

This is the playground for most of the jQuery related concepts. We would be using this playground throughout this article.

Next, we identify the element we would like to modify the contents of. Let’s modify the complete body of the page. From the Elements tab in the developer window, you would see that the element is this:

This element is uniquely defined through an id attribute bodyContent. We would use this id as a selector.

NOTE: Keep in mind that the attribute values are case sensitive – bodyContent is not the same as bodycontent.

Now, we would fetch data from Wikipedia’s JavaScript page and insert it into the jQuery page’s content. Go to the console tab and type the following command:

As you press enter, notice that the jQuery page’s entire content now has JavaScript page’s content.

Ignore the error – this is because our experiment resulted in implementing one object model more than once, which caused Wikipedia’s code to throw an error. Next, go back to the Elements tab and search for the bodyContent element again.

Notice the change in the entire HTML content of the element. It now looks like this:

You could also display an alert when the entire operation is successful through the load method’s complete function parameter. Go back to the console tab and type the following command:

alert(“Okay!!!”); }); Elements of load Method

The load() method of jQuery fetches HTML from the URL and uses the returned HTML to fill the selected elements; let’s look at a few elements.

Loading Page Fragments

The load() method also allows us to load a fragment of the content instead of the entire content. Let’s see how to do this.

Go ahead and give it a try to see the results for yourself. Also, go to the JavaScript page and search for the element by the id History. Verify whether the results are indeed accurate.

So what happened here? jQuery did load the entire contents of the url but parsed it to find the element suffixing the url and inserted only the element’s innerHTML contents into the destination element in the DOM.

Executing Scripts

There is a fundamental difference between when jQuery implements the load method with a selector appended to the url and without a selector appended to the url.

In the former case, the scripts from the url are executed. Whereas in the latter case, the scripts are omitted. Thus,

Conclusion – jQuery load()

So, we have covered the load() function of jQuery in this article. We have understood how the load method works behind the scenes and in-depth as well. It is recommended to practice the method more with different kinds of data. This will help you get a better understanding of how the function works.

Recommended Articles

This is a guide to jQuery load(). Here we discuss some of the examples of the load() method along with the Loading Page Fragments. You may also have a look at the following articles to learn more –

Update the detailed information about Learn The Types Of References In C# on the Moimoishop.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!