Posts

Showing posts with the label CSharp

Difference Between For and Foreach loop

For        1.   If you want to access object by Index then use for loop.        2.   To use For loop you must have know that how many times loop repeated. Foreach         1.  if you want to iterate object then use foreach loop .        2.  in for each no need to know about total loop repeating. Performance  wise for loop is faster then foreach.

How to Encrypt and Decript web.config connection string?

How to Encrypt and Decript  web.config connection string? web.config <connectionStrings>    <add name="connection" connectionString="data source=localhost;initial catalog=test;uid=sa;pwd=abcxyz"   providerName="System.Data.SqlClient" />  </connectionStrings> Add Two Button Encrypt and Decript  in asp.net and  write the code such as    protected void btnEncript_Click(object sender, EventArgs e)     {         Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(GetWebConfigMappedPath(), "/");         ConfigurationSection appSetting = config.GetSection("connectionStrings");         appSetting.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");         config.Save();       }     protected void btnDecript_Click(object sender, EventArgs e)     {         Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(GetWebConfigMappedPath(), "/"

What is Abstraction and Encapsulation

Abstraction : Hides the implementation details of your methods. Provides a base to variations in the application which can grow over a period of time. Abstraction is virtual class design. Before actually defining class, developer will think about what all properties, methods and event will be   there in my class. Example : public abstract class Automobile {  //Properties  public int DoorCount { .. }  public string EngineType { .. }  public float Height { .. }  public float GasTankSize { .. }  public float WheelBase { .. }  public float WheelSize { .. }  //Abstract Properties  public abstract string BodyType { get; }  //Methods  public float CalculateFuelEfficiency(int lastMileage); } The Automobile class is the interface, in that it defines an interface that classes will derive from. You can't directly instantiate it through new Automobile() because it's not an implementation. It's important to note the BodyType prope