Explain how properties differ from fields. Why would you expose public data through properties instead of fields?

1 Answer

Answer :

Properties allow validation code to execute when values are accessed or changed. This allows you to impose some measure of control over when and how values are read or changed. Fields cannot perform validation when being read or set.

Related questions

Description : Can an Interface contain fields?

Last Answer : No, an Interface cannot contain fields.

Description : Define what is fields?

Last Answer : A field is a variable that is associated with a class or with an instance of a class.

Description : Explain why you might use enums and constants instead of their associated literal values.

Last Answer : Enums and constants make code easier to read and maintain by substituting human-legible tokens for frequently used constant values.

Description : Explain when you might implement a shortcut menu instead of a main menu.

Last Answer : If every possible option is exposed on a main menu, the menu can become busy and hard to use. Shortcut menus allow less frequently used options to be exposed only in situations where they are likely to be used.

Description : Briefly describe the three types of user-developed controls and how they differ.

Last Answer : The three types of user-developed controls are inherited controls, user controls, and custom controls. An inherited control derives from a standard Windows Forms control and inherits the ... inherit only generic control functionality. All specific functionality must be implemented by the developer.

Description : How does C# differ from C++?

Last Answer : C# does not support the #include statement. It uses only using statement. In C#, the class definition does not use a semicolon at the end. C# does not support multiple code inheritance. Casting in ... used on string values. Command line parameters array behave differently in C# as compared to C++.

Description : Can an interface have properties?

Last Answer : Yes

Description : Write some code to declare and use properties.

Last Answer : // instance public string InstancePr { get { return a; } set { a = value; } } //read-only static public static int ClassPr { get { return b; } }

Description : Can properties hide base class members of the same name?

Last Answer : Yes

Description : Can properties have an access modifier?

Last Answer : Yes

Description : Name a few string properties.

Last Answer : trim, tolower, toupper, concat, copy, insert, equals, compare. 

Description : Define what are the advantages of getting and set properties in C#?

Last Answer : 1. The get property accessor is used to return the property value. 2. The set property accessor is used to assign a new value.

Description : Define what Command is used to implement properties in C#?

Last Answer : get & set access modifiers are used to implement properties in c#.

Description : Briefly explain the difference between Public (public), Friend (internal), and Private (private) access levels as they apply to user-defined types and members.

Last Answer : In user-defined types, Public (public) classes can be instantiated by any element of the application. Friend (internal) classes can be instantiated only by members of the same assembly, and Private ( ... the same assembly, and Private (private) members can be accessed only from within the type. 

Description : Explain how to convert data in legacy code page formats to the Unicode format.

Last Answer : You can use the Encoding.Convert method to convert data between encoding types. This method requires instances of both encoding types and an array of bytes that represents the data to be converted. ... GetBytes method and can convert an array of bytes back to chars with the Encoding.GetChars method.

Description : In terms of constructors, what is the difference between: public MyDerived() : base() an public MyDerived() in a child class?

Last Answer : Nothing

Description : What does this do? Public Foo() : this(12, 0, 0)

Last Answer : Calls another constructor in the list 

Description : An operator declaration must include a public and static modifier, can it have other modifiers?

Last Answer : No

Description : What is public accessibility?

Last Answer : There are no access restrictions. 

Description : Define what are the differences between static, public and void in C#?

Last Answer : 1. Static classes/methods/variables are accessible throughout the application without creating an instance. The compiler will store the method address as an entry point. 2. Public methods or variables are accessible ... 3. The void is used for the methods to indicate it will not return any value.

Description : Describe how to use a DataView to filter or sort data.

Last Answer : You can apply sort criteria to a DataView by setting the Sort property to the name of a column or columns to be sorted by. The data represented in a DataView object can be filtered by setting the RowFilter property to a valid filter expression.

Description : How can you manage data currency on a form with several bound controls?

Last Answer : Every data source on a form has an associated CurrencyManager object that keeps that of the current record with respect to bound controls. For convenience, all of the CurrencyManager objects ... property. The Position of the CurrencyManager can be changed, allowing navigation through the records. 

Description : Briefly contrast connected and disconnected data access in ADO.NET.

Last Answer : In ADO.NET, connected data access is available through the DataReader, which is a lightweight class designed to provide very fast and efficient data access. It is severely limited, however, in ... to update the database and keeping the connection open just long enough to execute those commands.

Description : What are the major components of a Data Provider, and what function does each fulfill?

Last Answer : An ADO.NET Data Provider is a suite of components designed to facilitate data access. Every Data Provider minimally includes a Connection object that provides the actual connection to the data ... only, read-only access to a database, and a DataAdapter that facilitates disconnected data access.

Description : Can you store multiple data types in System.Array?

Last Answer : No. 

Description : What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?

Last Answer : SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix. ... on top of the OLE layer, so it's not as fastest and efficient as SqlServer.NET.

Description : Can you store multiple data types in System.Array?

Last Answer : No.

Description : What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?

Last Answer : SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix. ... on top of the OLE layer, so it's not as fastest and efficient as SqlServer.NET.

Description : Can you store multiple data types in System.Array?

Last Answer : No.

Description : Define what is meant by data encapsulation?

Last Answer : Data encapsulation also referred to as data hiding, is the mechanism whereby the implementation details of a class are kept hidden from the user. The user can only perform a restricted set of operations on the hidden members of the class by executing special functions called methods.

Description : Define what are the two data types available in C#?

Last Answer : Value type Reference type

Description : Teenage risque' expose', explain or run like hell?

Last Answer : When I was 13, I was too busy playing Pokemon and being picked on to worry about shoving my hand down anyone’s Daisy Dukes.

Description : What are three test cases you should go through in unit testing?

Last Answer : 1. Positive test cases (correct data, correct output). 2. Negative test cases (broken or missing data, proper handling). 3. Exception test cases (exceptions are thrown and caught properly).

Description : What are three test cases you should go through in unit testing? 

Last Answer : 1. Positive test cases (correct data, correct output). 2. Negative test cases (broken or missing data, proper handling). 3. Exception test cases (exceptions are thrown and caught properly).

Description : Explain how to retrieve information from the configuration file at run time. How would you store information in the configuration file at design time?

Last Answer : You must first create an instance of AppSettingsReader to read the configuration file. You can then call the GetValue method to read values represented in the configuration file. To add configuration ... used to retrieve the entry. The value can be changed between executions of the application.

Description : Explain how to use the PrintPreviewDialog control to display a preview of a printed document before it is printed.

Last Answer : You display a preview of a printed document with the PrintPreviewDialog control by first setting the PrintDocument property of the PrintPreviewDialog instance to the PrintDocument you want to preview, then by calling the PrintPreviewDialog.Show command to display the dialog box. 

Description : Explain the difference between Globalization and Localization.

Last Answer : Globalization refers to the application of culture-specific format to existing data. Localization refers to providing new culture-specific resources and retrieving the appropriate resources based on the culture setting. 

Description : Explain how to use the HelpProvider component to provide help for UI elements.

Last Answer : You can provide either a HelpString or a help topic for UI elements with the HelpProvider. The HelpProvider provides HelpString, HelpKeyWord, and HelpNavigator properties for each control on the form. If ... particular element is displayed when the element has the focus and the F1 key is pressed.

Description : Explain how to use the Begin and End methods on a Web Service to make an asynchronous method call.

Last Answer : Every public Web method on a Web Service can be called either synchronously or asynchronously. To make an asynchronous call to a Web method, you call the method named Begin, where is the name of ... returned by Begin. This will allow you to retrieve the actual data returned by the Web method.

Description : Describe an abstract class and explain when one might be useful.

Last Answer : An abstract class is a class that cannot be instantiated but must be inherited. It can contain both implemented methods and abstract methods, which must be implemented in an inheriting class. ... common interface for other methods, and leave more detailed implementation up to the inheriting class.

Description : Briefly explain encapsulation and why it is important in object-oriented - programming.

Last Answer : Encapsulation is the principle that all of the data and functionality required by an object be contained by that object. This allows objects to exist as independent, interchangeable units of functionality without maintaining dependencies on other units of code.

Description : Briefly explain how to convert a string representation of a number to a numeric type, such as an Integer or a Double.

Last Answer : All numeric data types have a Parse method that accepts a string parameter and returns the value represented by that string cast to the appropriate data type. You can use the Parse method of each data type to convert strings to that type.

Description : Explain what a delegate is and how one works. 

Last Answer : A delegate acts like a strongly typed function pointer. Delegates can invoke the methods that they reference without making explicit calls to those methods.

Description : Explain when a type conversion will undergo an implicit cast and when you must perform an explicit cast. What are the dangers associated with explicit casts?

Last Answer : Types can be implicitly converted when the conversion can always take place without any potential loss of data. When a potential loss of data is possible, an explicit cast is required. If an explicit cast is improperly performed, a loss of data precision can result, or an exception can be thrown.

Description : Explain what constructors and destructors are and describe what they are used for.

Last Answer : The constructor is the method that initializes a class or structure and is run when a type is first instantiated. It is used to set default values and perform other tasks required by the class. ... reclaimed by garbage collection. It contains any code that is required for cleanup of the object. 

Description : Briefly explain what is meant by a reference type and a value type.

Last Answer : A value type holds all of the data represented by the variable within the variable itself. A reference type contains a reference to a memory address that holds the data instead of the actual data itself. 

Description : Explain ACID rule of thumb for transactions.

Last Answer : A transaction must be: 1. Atomic - it is one unit of work and does not dependent on previous and following transactions. 2. Consistent - data is either committed or roll back, no in-between ... . Durable - the values persist if the data had been committed even if the system crashes right after. 

Description : Explain the three services model commonly know as a three-tier application.

Last Answer : Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).

Description : Explain sizeof and typeof.

Last Answer : typeof obtains the System.Type object for a type and sizeof obtains the size of a type.

Description : Explain ACID rule of thumb for transactions.

Last Answer : A transaction must be: 1. Atomic - it is one unit of work and does not dependent on previous and following transactions. 2. Consistent - data is either committed or roll back, no in-between ... 4. Durable - the values persist if the data had been committed even if the system crashes right after.