TechTips .NET/ CSLA.NET / ASP.NET / VB.NET / C# / SQL Server / MySql / Android
  • Oct
    12

     

    Hi friends.. sometime back I had a discussion with few of my friends on different topics on OOPS. Just thought to put a post of some of the important facts which might help others as well.  Starting with Abstract classes. Will be writing on more topics in next posts.
    Abstract Classes

    1. Abstract classes can have a non abstract ctor and they can’t be instantiated.
    2. Since abstract classes can’t be instantiated one should not use Public and Protected Internal modifier with Abstract class Ctor.
    3. Abstract class can be derived from a concrete class.
    4. Abstract class can have non abstract members (methods, events, properties) but non abstract class can’t have abstract members.
    5. An abstract class may contain abstract methods and accessors.
    6. An abstract method is implicitly a virtual method.
    7. Static and Virtual modifiers can’t be used with abstract methods
    8. An abstract inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.
    9. Abstract classes can have concrete static methods.

    Hope this helps..Please put your comments and any additional info about abstract class which may help others as well.

    No Comments
  • Jan
    17


    So what is the difference between CONST and READONLY? Let’s examine the difference between these two with an example.


    So we can clearly see that we can initialize readonly variables during the declaration and in the constructor of the class. So its possible to initialize readonly variables once at run time but we can’t change value of const variables.

    Happy coding!

    7 Comments
  • Aug
    23

    Hi,

    Recently I need to show multi-line string in a datagridview cell. To achieve that we need to write code in CellFormatting event of DataGridview. Following is the code

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.Value.Equals("Error"))
                {
                    e.CellStyle.BackColor = Color.Red;
                    e.CellStyle.ForeColor = Color.White;
    
                }
                else
                {
                    if ((!e.Value.Equals("OK")) && e.ColumnIndex==2)
                    {
                        e.CellStyle.BackColor = Color.Green;
                        e.CellStyle.ForeColor = Color.White;
                        e.CellStyle.WrapMode = DataGridViewTriState.True;
                        dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
    
                    }
    
                }
            }
    

    I hope this help!

    Kshitij

    3 Comments
  • Dec
    8

    Hi,

    Few days back i needed a code snippet to write a text in starting of all files in a directory. Searched net but could not find any working code. Then i decide to write my own code and come up with following code.

    I hope this will help guys who are looking to do same.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace AddTextToFiles
    {
        class Program
        {
            private static DirectoryInfo ds;
            static void Main(string[] args)
            {
                Console.WriteLine("*********************Written By Kshitij Sharma ***********************");
                Console.WriteLine("Please Enter the path and Press enter ");
                string sPath = Console.ReadLine();
                Console.WriteLine("Please Enter <B style="BACKGROUND-COLOR: #a0ffff; COLOR: black">Text</B> ");
                string sText = Console.ReadLine();
                addText(sPath,sText);
                Console.WriteLine("*****************Reach Me @ k.sharma78@gmail.com****************");
                Console.Read();
            }
    
            private static void addText(string pth,string txt)
            {
                try
                {
    
                    if (!string.IsNullOrEmpty(pth))
                    {
                        ds = new DirectoryInfo(pth);
                    }
                    else
                    {
                        ds = new DirectoryInfo("c:\\testfiles");
                    }
                    if (string.IsNullOrEmpty(txt))
                    {
                        txt = "<!--#Include File=\"CheckSQL.inc\"-->";
                    }
                    foreach (FileInfo f in ds.GetFiles("*.asp"))
                    {
                        Console.WriteLine("Writing to file-->" + f.Name);
                        string strPath = ds.Root + ds.Name + "\\" + f.Name;
                        StreamReader sr = new StreamReader(strPath);
                        string fileContent = sr.ReadToEnd();
                        sr.Close();
                        StreamWriter sw = new StreamWriter(strPath, false);
                        StringReader gr = new StringReader(fileContent);
                        sw.WriteLine(txt);
                        sw.WriteLine(gr.ReadToEnd());
                        sw.Close();
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.Read();
                }
            }
        }
    }
    
    2 Comments

Translate

EnglishFrenchGermanHindiItalianPortugueseRussianSpanish
| More