I have been to an interview and was asked this question - is there any difference adding or removing the static
keyword in these classes?
I know what static
means but my understanding of this point is weak.
class Program
{
static void Main(string[] args)
{
aAsposeNew.MultipleInstancesProblem();
Console.ReadLine();
}
}
public static class aAsposeNew
{
public static void MultipleInstancesProblem()
{
var task1 = Task.Run(() => CreateDocument("document1.pdf"));
var task2 = Task.Run(() => CreateDocument("document2.pdf"));
var task3 = Task.Run(() => CreateDocument("document3.pdf"));
}
public static void CreateDocument(string documentName)
{
var doc = new Document();
doc.Pages.Add();
var table = new Aspose.Pdf.Table();
var row = table.Rows.Add();
table.ColumnWidths = "600";
var hf =
new HtmlFragment(@"<ul>
<li>Internal HR Meeting Outcome</li>
<li>Internal HR Meeting Outcome January 2015</li>
</ul>");
var cell = row.Cells.Add();
cell.Paragraphs.Add(hf);
doc.Pages[1].Paragraphs.Add(table);
doc.Save(@"C:\Output\" + documentName);
}
}
and without the static
keyword:
class Program
{
static void Main(string[] args)
{
aAsposeNew aAN = new aAsposeNew();
aAN.MultipleInstancesProblem();
Console.ReadLine();
}
}
public class aAsposeNew
{
public void MultipleInstancesProblem()
{
var task1 = Task.Run(() => CreateDocument("document1.pdf"));
var task2 = Task.Run(() => CreateDocument("document2.pdf"));
var task3 = Task.Run(() => CreateDocument("document3.pdf"));
}
public void CreateDocument(string documentName)
{
var doc = new Document();
doc.Pages.Add();
var table = new Aspose.Pdf.Table();
var row = table.Rows.Add();
table.ColumnWidths = "600";
var hf =
new HtmlFragment(@"<ul>
<li>Internal HR Meeting Outcome</li>
<li>Internal HR Meeting Outcome January 2015</li>
</ul>");
var cell = row.Cells.Add();
cell.Paragraphs.Add(hf);
doc.Pages[1].Paragraphs.Add(table);
doc.Save(@"C:\Output\" + documentName);
}
}