Null-collation(??) is an important operator in C#. As per the MSDN definition: The ?? operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types. It returns the left-hand operand if the operand is not null; otherwise, it returns the right operand. The C# Null Coalescing Operator (??) is a binary operator that simplifies checking for null values. It is used to assign a default value to a variable when the value is null.
Ex:
static void Main(string[] args)
{
string name = "ABC";
string myname = name ?? "EFG";
Console.WriteLine(myname);
Console.ReadLine();
}
O/P : ABC
Ex:
static void Main(string[] args)
{
string name = null;
string myname = name ?? "EFG";
Console.WriteLine(myname);
Console.ReadLine();
}
O/P : EFG
ORM(Object Relation Mapping):
Entity Framework an NHiberante are ORMs. It means that you do not operate by SQL connections, commands, parameters - ORM tool does it for you and it allows to map your database structure in OOP manner: you can add, read, update, delete records in your DB using objects in C#.
Most Used ORMs ??
- NHibernate: This remains my best bet and I personally feel it is the best ORM. This works well with Oracle database.
- Entity Framework: Microsoft’s answer to NHibernate. Works well with SQL, but still a step behind NHibernate.
- LINQ to SQL: A light version of ORM. Cannot be termed as an ORM in itself, but can use its features to achieve ORM’s functionality.
static void Main(string[] args)
{
int num, x;
Console.WriteLine("Enter the Number ");
num = int.Parse(Console.ReadLine());
Console.WriteLine("The Factors are : ");
for (x = 1; x <= num; x++)
{
if (num % x == 0)
{
Console.WriteLine(x);
}
}
Console.ReadLine();
}
}
//Output--1,3,9,,27
Remove Duplicate characters
class Program
{
static void Main()
{
string value1 = RemoveDuplicateChars("Csharpstar");
Console.WriteLine(value1);
}
static string RemoveDuplicateChars(string key)
{
// --- Removes duplicate chars using string concats. ---
// Store encountered letters in this string.
string table = "";
// Store the result in this string.
string result = "";
// Loop over each character.
foreach (char value in key)
{
// See if character is in the table.
if (table.IndexOf(value) == -1)
{
// Append to the table and the result.
table += value;
result += value;
}
}
return result;
}
}
//Input: Csharpstar
//Output: Csharpt
2) Calculate power of number using recursion in C#
class Program
{
static void Main(string[] args)
{
double x = Power(2, 3);
Console.WriteLine(x);
Console.ReadLine();
}
internal static double Power(double @base, int exponent)
{
if (exponent < 0)
{
Console.Error.WriteLine("Usage of this function is limited to positive exponents only");
throw new Exception();
}
else if (exponent == 1)
{
return @base;
}
else if (exponent == 0)
{
return 1;
}
else
{
return @base * Power(@base, exponent - 1);
}
}
}
O/P--8
What Happens If You Delete a Table That Is Used by a View?
http://dba.fyicenter.com/faq/sql_server/Deleting_a_Table_That_Is_Used_by_a_View.html
MVC How to bundle html templates of type “text/html” or cshtml?
can u put both js and css files in one bundle config file?
what are the configuration are ther ein bundle config
difference
select sum(1) from Policy-- Output-10
select sum(2) from Policy-- Output-20
select count(*) from Policy-- Output-10
How do i print the count of repeated string count?
https://www.dotnetperls.com/duplicate-chars
how indexes are working internally
No comments:
Post a Comment