In c# language, ternary operator (?) use to check a conduction, so other name of ternary operator is conditional operator, which work as a if statement. This operator compares two values. It produces a third value that depends on the result of the comparison. At compile-time, the C# compiler translates the ternary expression into branch statements such as brtrue.
public string check(string name, int pass) //Create function
//Use ternary operator ?
//condition true then reply “Welcome Arvind”
//condition falls then reply “Invalid Login or Password”
return name == “arvind” && pass==123 ? “Welcome Arvind” : “Invalid Login or Password”;
Example Class Hierarchy
Let’s assume the following simple class hierarchy with classes A, B and C for the discussions in this text. A is the super- or base class, B is derived from A and C is derived from class B. In some of the easier examples, we will only refer to a part of this class hierarchy.
How does output caching work in ASP.NET?
Output caching is a powerful technique that increases request/response throughput by caching the content generated from dynamic pages. Output caching is enabled by default, but output from any given response is not cached unless explicit action is taken to make the response cacheable. Continue reading
In an interface class, all methods are
abstract without implementation whereas in an
abstract class, some methods we can define concrete. In interface, no accessibility modifiers are allowed. An
abstract class may have accessibility modifiers. Interface and
abstract class are basically a set of rules which you have to follow in case you are using them (inheriting them). Continue reading
What is the significance of Finalize method in .NET?
.NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources (example: Windows API created objects, File, Database connection objects, COM objects, etc.) are outside the scope of .NET Framework. We have to explicitly clean our resources. For these types of objects, .NET Framework provides
Object.Finalize method, which can be overridden and clean up code for unmanaged resources can be put in this section? Continue reading
This article on Interview Questions and Answers of MVC basically covers most of the MVC 2, MVC 3 and MVC 4 topics that are most likely to be asked in job interviews/tests/exams.
XmlIgnore: If you specify XmlIgnore on a field, that field will be ignored when serialized.
XmlAttribute:This Specifies that the XmlSerializer must serialize the class member as an XML attribute.
XmlRoot:Controls XML serialization of the attribute target as an XML root element. You can use the word
XmlRoot in your code instead of the longer XmlRootAttribute.
XmlElementattribute: Indicates that a public field or property represents an XML element when the XmlSerializer serializes or deserializes the object that contains it. Set the element name and namespace of the XML element. By applying an XmlElementAttribute to an array, you instruct the XmlSerializer to serialize the array as a series of XML elements, instead of a nested set of elements. Continue reading
xsd.exe tool which gets installed with the Windows SDK into a directory something similar to:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin
On the first run, you use
xsd.exe and you convert your sample XML into a XSD file (XML schema file):
This gives you
yourfile.xsd, which in a second step, you can convert again using
xsd.exe into a C# class:
xsd yourfile.xsd /c
This should give you a file
yourfile.cs which will contain a C# class that you can use to deserialize the XML file you’re getting – something like:
XmlSerializer serializer = new XmlSerializer(typeof(msg));
msg resultingMessage = (msg)serializer.Deserialize('yourfile.xml');
XML file that I used is Continue reading
Converting your entire class data to XML and then XML to class back is very helpful when you are doing some project . Here I am explaining how to convert your class data to XML in C# 4.0 using System.Xml.Linq.