VB.Net vs C# Syntax
Click here to view
Dotnet, DotnetCore, Azure, C#,VB.net, Sql Server, WCF, MVC ,Linq, Javascript and Jquery
12 September 2013
5 September 2013
Access Modifiers in c#
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
The type or member can be accessed only by code in the same class or struct.
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
The type or member can be accessed by any code in the same assembly, but not from another assembly.
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.
Extension Methods in C#
Extension Methods in C#
Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type.
Remove $ from the string using Extension Methods in C#
using System;
using System.Windows.Forms;
namespace ExtensionMethodsExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ExtensionMethodExample();
}
private void ExtensionMethodExample()
{
string dollarval = "2000$";
dollarval = dollarval.RemoveDollarSign();
}
}
public static class RemoveDollar
{
public static String RemoveDollarSign(this string dollarval)
{
string val = dollarval.Replace("$", "");
return val;
}
}
}
Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type.
Remove $ from the string using Extension Methods in C#
using System;
using System.Windows.Forms;
namespace ExtensionMethodsExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ExtensionMethodExample();
}
private void ExtensionMethodExample()
{
string dollarval = "2000$";
dollarval = dollarval.RemoveDollarSign();
}
}
public static class RemoveDollar
{
public static String RemoveDollarSign(this string dollarval)
{
string val = dollarval.Replace("$", "");
return val;
}
}
}
Subscribe to:
Posts (Atom)
Implementing OAuth validation in a Web API
I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...
-
ViewBag, ViewData, TempData and View State in MVC ASP.NET MVC offers us three options ViewData, ViewBag and TempData for passing data from...
-
// Export Datatable to Excel in C# Windows application using System; using System.Data; using System.IO; using System.Windows.Forms; ...