Posts

Showing posts from July, 2017

C# Coding Standards and Naming Conventions

1. use PascalCasing for class names and method names. public Class TestClass {        public void TestMethod()       {            //--------------       } } 2 use camelCasing for method arguments and local variables. public Class TestClass {        public void TestMethod(UserDetail userDetail)       {            int usersCount=userDetail.items.count             //-----       } } 3. use PascalCasing for abbreviations 3 characters or more (2 chars are both uppercase)     HtmlHelper htmlHelper;     FtpTransfer ftpTransfer;     UIControl uiControl; Why: consistent with the Microsoft's .NET Framework. Caps would grap visually too much attention. 4. use...

Boxing and Unboxing

Boxing: Boxing is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type. When the CLRlic boxes a value means when CLR is converting a value type to Object Type, it wraps the value inside a System.Object and stores it on the heap area in application domain. Example: public void fnBoxing() {        int i=5;        object o=i; //implicit Boxing } Unboxing: Unboxing is also a process which is used to extract the value type from the object or any implemented interface type. Boxing may be done implicitly, but unboxing have to be explicit by code. Example: public void fnUnboxing() {     object  o=5;    int i=(int)o;//explicit Unboxing  }

Difference between an abstract class and interfaces

Image
Difference between an abstract class and interfaces A class can implement any number of interfaces but a subclass can at most use only one abstract class. An abstract class can have non-abstract methods (concrete methods) whereas all methods of interfaces must be abstract. An abstract class can declare or use any variables whereas an interface is not allowed to do so. An abstract class can have a constructor declaration whereas an interface cannot. An abstract class is allowed to have all access modifiers for all of its member declarations whereas in an interface we cannot declare any access modifier (including public) since all the members of an interface are implicitly public.

c# - How to increase the max upload file size in ASP.NET?

If you are using IIS for hosting your application, then the default upload  size if 4MB. To increase it, please use this below section in your web.confg. <configuration> <system.web> <httpRuntime maxRequestLength = " 4096 " /> </system.web> </configuration> " 4096 " is in KB. For IIS7 and above, you also need to add the lines below: <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength = "1073741824" /> </requestFiltering> </security> </system.webServer> Note:  maxAllowedContentLength  is measured in bytes while  maxRequestLength  is measured in kilobytes, which is why the values differ in this config example. (Both are equivalent to 1 GB.)

SQL Tips and Tricks: Indexing Dos and Don’ts

SQL Tips and Tricks: Indexing Dos and Don’ts : Indexing is such a large subject that getting a handle on what to do and what not to do when you're developing your indexing strategie...

Custom error mode off in web config

Three error modes in which an ASP.NET application can work: 1) Off Mode 2) On Mode 3) RemoteOnly Mode The Error mode attribute determines whether or not an ASP.NET error message is displayed. By default, the mode value is set to "RemoteOnly". Off Mode When the error attribute is set to "Off", ASP.NET uses its default error page for both local and remote users in case of an error. <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <customErrors mode="Off" /> </system.web> </configuration> On Mode In case of "On" Mode, ASP.NET uses user-defined custom error page instead of its default error page for both local and remote users. If a custom error page is not specified, ASP.NET shows the error page describing how to enable remote viewing of errors. <? xml version =" 1.0" encoding =" utf-8" ? > < configuration ...

C# Tips that improve code efficiency and productivity

C# is a wonderful programming language; This tips that you can use to improve code efficiency, make your code more compact and achieve productivity. 1. Ternary Operator (?:) Ternary operator. The ternary operator tests a condition. It compares 2 values. It produces a third value that depends on the result of the comparison. The ternary effect can be accomplished with if-statements or other constructs. The ternary operator provides an elegant and equivalent syntax form to the if-statement. Example. One use of a ternary is to initialize a variable with the result of the expression. The C# compiler translates the ternary expression into branch statements such as brtrue. IL However: The high-level ternary statement is useful because it allows you to condense multiple if-statements and reduce nesting. Tip: It does not actually eliminate branching. It simplifies the high-level representation of the branching.   Based on: .NET 4.6 C# progra...

How to improve performance of code in c#

1. Knowing when to use StringBuilder You must have heard before that a StringBuilder object is much faster at appending strings together than normal string types. The thing is StringBuilder is faster mostly with big strings. This means if you have a loop that will add to a single string for many iterations then a StringBuilder class is definitely much faster than a string type. However if you just want to append something to a string a single time then a StringBuilder class is overkill. A simple string type variable in this case improves on resources use and readability of the C# source code. Simply choosing correctly between StringBuilder objects and string types you can optimize your code. 2. Comparing Non-Case-Sensitive Strings In an application sometimes it is necessary to compare two string variables, ignoring the cases. The tempting and traditionally approach is to convert both strings to all l...

Differnce between JavaScript jQuery and AJAX?

JavaScript  JavaScript is a client-side (in the browser) scripting language.  JavaScript lets you supercharge your HTML with animation, interactivity, and dynamic visual effects  JavaScript can make web pages more useful by supplying immediate feedback.  JavaScript is the common term for a combination of the ECMAScript programming language plus some means for accessing a web browser's windows and the document object model (DOM).  JavaScript was designed to add interactivity to HTML pages  Everyone can use JavaScript without purchasing a license  jQuery  jQuery is a library/framework built with JavaScript.  It abstracts away cross-browser compatibility issues and it emphasises unobtrusive and callback-driven JavaScript programming  jQuery (website) is a JavaScript framework that makes working with the DOM easier by building many high level functionality that can be used to search and interact with the DOM  jQuery imp...

ASP.NET page cycle

Each request for an .aspx page that hits IIS is handed over to the HTTP Pipeline. The HTTP Pipeline is a chain of managed objects that sequentially process the request and convert it to plain HTML text content. The starting point of a HTTP Pipeline is the HttpRuntime class. The ASP.NET infrastructure creates each instance of this class per AppDomain hosted within the worker process. The HttpRuntime class picks up an HttpApplication object from an internal pool and sets it to work on the request. It determines what class handles the request. The association between the resources and handlers are stored in the configurable file of the application. In web.config and also inmachine.config you will find these lines in section. If you run through the following program then it will be much easier to follow: <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/> This extension can be associated with Han...