Thursday, 9 November 2017

?? in C# (double question mark operator in C#) Or null coalescing operator

null coalescing operator


The operator "??", yes two question marks. called as  "null-coalescing" or just the double question mark operator.

According to the Microsoft, help page: "The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand."

eg : var result = answer1 ?? answer2;
            can also be written as below
var result = answer1 != null ? answer1 : answer2;

if answer1 is not null =>
     result = answer1

if answer1 is null =>
   result = answer2

?? will be better uasable when we have to check for multiple null values for a result

string result = answer1 ?? answer2 ?? answer3 ?? answer4;
For more information please check
https://stackoverflow.com/questions/446835/what-do-two-question-marks-together-mean-in-c

Thursday, 13 July 2017

Process with an ID ???? is not running in visual studio 2015

Possible Solution 1: 

  • Close VS.
  • Navigate to the folder of the solution and delete the hidden .vs folder.
  • Restart VS.
  • Hit F5 and IIS Express should load as normal, allowing you to debug.
Possible Solution 2: 
  • Close all instances of Visual Studio
  • Rename the IISExpress folder (in my PC is in C:\Users\jmelosegui\Documents)
  • Add the _CSRUN_DISABLE_WORKAROUNDS Environment System variable with the value of 1. Here is how.
  • Start Visualstudio in administrator mode
Possible Solution 3:
  • open vs as an administrator
  • right click project and click on unload project
  • again right click project and click on open edit.... csproj
  • find the code below and delete it $
    <DevelopmentServerPort>63366</DevelopmentServerPort>
    <DevelopmentServerVPath>/</DevelopmentServerVPath>
    <IISUrl>http://localhost:63366/</IISUrl>
    
  • save and close the file .csproj
  • right click project and reload it
Source : https://stackoverflow.com/questions/26424902/process-with-an-id-is-not-running-in-visual-studio-professional-2013-update


Thursday, 13 March 2014

C# Structure

Why C# structures cannot have explicit parameterless constructor?

Answer: structures are value types. value types in C# contains default values. 
example: integer which by default value is numerical zero.

Remember : Structures can contain parametrized constructor.

more on C# structure

  • To define a structure we will use C# keyword called "struct"
  • structure is a value type. (its a protocol)
  • when we instantiated structure , it will be allocated in stack memory.(because all struct is a value type and all value types are will be allocated a stack memory)
  • structure cannot contain destructor.(only class can have destructor) WHY? 

Answer: struct being value type, are not subject to garbage collection. for more click here
  • we cannot use abstract and sealed keyword while defining a structure. C# Struct does not support inheritance.
  • we cannot use protected and protected internal access modifier for structures or structure members because it will not support inheritance.
  • To create an object for structure we don't required to use new operator.(When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized.)


C#.NET Interface

C Sharp - Interface

  • By default Interface is Internal
  • All interface members are implicitly public and abstract so the members of the interface never specify access modifier.
  • Interfaces do not have an implementation of members(protocol). so interfaces cannot have data fields and also interfaces do not have constructors.
  • It is illegal to allocate Interface types.
  • Interfaces has read/write properties
  • Interfaces can contain event and indexer definitions.




Monday, 24 February 2014

ASP.NET Web API


What is ASP.NET Web API?


ASP.NET Web API is a framework for building web APIs on top of the .NET Framework.

What Model means in ASP.NET Web API?


A model is an object that represents the data in your application. ASP.NET Web API can automatically serialize your model to JSON, XML, or some other format, and then write the serialized data into the body of the HTTP response message. As long as a client can read the serialization format, it can deserialize the object. Most clients can parse either XML or JSON. Moreover, the client can indicate which format it wants by setting the Accept header in the HTTP request message.

What Controller means in ASP.NET Web API?


In Web API, a controller is an object that handles HTTP requests. We'll add a controller that can return either a list of products or a single product specified by ID.


Source

Monday, 25 March 2013

Constructors in C Sharp


  • Constructors are the core concept of Object Oriented Language, So the compiler generates a default constructor with default field values at compile time, only if there is no custom constructor was created.
  • If the class or struct has a custom constructor , the compiler silently removes the default constructor.
  • When a class or struct is created , its constructor is called(Invoked when a class is instantiated and objects memory location is created).
  • Constructors can be overloaded and they don't return values so no return type is used including void.
  • we can call one constructor from another using 'this' keyword.
  • Car(int modelNumber) :  this() {  }
  • We can also use 'base' keyword if the class is inherited and wants the parent class constructor values to be loaded to child class.
  • Constructors should be public so that values will be assigned to current state(fields).
  • If private, we cannot instantiate the class(because the constructor will not be available or not accessible outside of that class.)
  • we can also create static constructor but only static fields can be assigned.
  • If struct , parameter constructors are not allowed.
  • It is legal to create custom constructor(struct type) with no parameters. As struct type is value type 'new' keyword to allocate memory object is optional.
  • Remember: Static constructors will be executed at random time but before the class is instantiated.

Sunday, 24 March 2013

What is the difference between runtime and compile time?


Answer: Runtime and compile time are programming terms that refer to different stages of software program development. In order to create a program, a developer first writes source code, which defines how the program will function. Small programs may only contain a few hundred lines of source code, while large programs may contain hundreds of thousands of lines of source code. The source code must be compiled into machine code in order to become and executable program. This compilation process is referred to as compile time.
A compiled program can be opened and run by a user. When an application is running, it is called runtime.
The terms "runtime" and "compile time" are often used by programmers to refer to different types of errors. A compile time error is a problem such as a syntax error or missing file reference that prevents the program from successfully compiling. The compiler produces compile time errors and usually indicates what line of the source code is causing the problem.
If a program's source code has already been compiled into an executable program, it may still have bugs that occur while the program is running. Examples include features that don't work, unexpected program behavior, or program crashes. These types of problems are called runtime errors since they occur at runtime.

Source: PC.net