Type.GetType("TheClass");
Run Code Online (Sandbox Code Playgroud)
null
如果namespace
不存在则返回如下:
Type.GetType("SomeNamespace.TheClass"); // returns a Type object
Run Code Online (Sandbox Code Playgroud)
有没有办法避免给出这个namespace
名字?
如何检查节点是否具有特定属性.
我做的是:
string referenceFileName = xmlFileName;
XmlTextReader textReader = new XmlTextReader(referenceFileName);
while (textReader.Read())
{
XmlNodeType nType = textReader.NodeType;
// if node type is an element
if (nType == XmlNodeType.Element)
{
if (textReader.Name.Equals("Control"))
{
if (textReader.AttributeCount >= 1)
{
String val = string.Empty;
val = textReader.GetAttribute("Visible");
if (!(val == null || val.Equals(string.Empty)))
{
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否有任何功能来检查给定属性是否存在?
如何在 C# 中测试性能?
我现在所知道的就是使用:
Stopwatch sw = new Stopwatch();
sw.Start();
{
//code to test
}
sw.Stop();
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以做到这一点还是上述方法错误?
我有一些图像,我手动添加到imageList Cotrol.现在我需要从imageList中删除thart图像,具体取决于键索引并设置为面板背景.
我该怎么办
我想限制其他应用程序使用我编写的dll函数.
例如.如果我有data.dll包含两个函数.
public void InsertInToDatabse();
public void ClearDatabase();
Run Code Online (Sandbox Code Playgroud)
现在如果我的应用程序调用了InsertInToDatabse()并正在做其他工作,直到这个时候,如果其他一些应用程序通过引用database.dll调用ClearDatabase(),那么数据库就会被废弃.那么如何限制对这些函数的调用呢第三方申请?
我正在使用itextsharp dll将HTML转换为PDF.
HTML有一些Unicode字符,如α,β...当我尝试将HTML转换为PDF时,Unicode字符不会显示在PDF中.
我的功能:
Document doc = new Document(PageSize.LETTER);
using (FileStream fs = new FileStream(Path.Combine("Test.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
{
PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.NewPage();
string arialuniTff = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts),
"ARIALUNI.TTF");
BaseFont bf = BaseFont.CreateFont(arialuniTff, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font fontNormal = new Font(bf, 12, Font.NORMAL);
List<IElement> list = HTMLWorker.ParseToList(new StringReader(stringBuilder.ToString()),
new StyleSheet());
Paragraph p = new Paragraph {Font = fontNormal};
foreach (var element in list)
{
p.Add(element);
doc.Add(p);
}
doc.Close();
}
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我在表单上添加了一个usercontrol.当我签this.parentForm
入userControl构造函数时,它给出了一个空引用
我的userControl代码就像
public UserControl1()
{
InitializeComponent();
if (this.ParentForm != null)//ParentReference is null
{
MessageBox.Show("Hi");//Does Not get Called
}
}
Run Code Online (Sandbox Code Playgroud) 我想在物理上保存在磁盘上之前压缩文件.
我尝试使用压缩和解压缩方法(MSDN示例代码),但所有方法都需要一个已经物理存储在磁盘上的文件.
我有一个应用程序经常从Access数据库中读取数据,有没有办法使用连接池?
我的Open Databse方法: -
private bool OpenDatabaseConnection(string databaseName)
{
try
{
string connectionString = "Provider = Microsoft.Jet.OLEDB.4.0; " +
"Data Source = " + databaseName + ";";
settingsDbConn = new OleDbConnection(connectionString);
settingsDbConn.Open();
}
catch (Exception)
{
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud) public bool StoreInExecel(String name,String csFIleName)
{
int cellno = ;//Initialize to current row no
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = (Microsoft.Office.Interop.Excel.Workbook)excelApp.Workbooks.Add(Missing.Value);
Worksheet worksheet;
// Opening excel file
workbook = excelApp.Workbooks.Open(fileName, 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
// Get first Worksheet
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets.get_Item(1);
// Setting cell values
((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[cellno,"B"]).Value2 = "5";
((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[cellno,"B"]).Value2 = "7";
workbook.Save();
workbook.Close(0, 0, 0);
//excelApp.Quit();
return true;
}
Run Code Online (Sandbox Code Playgroud)
我想将“cellno”初始化为 excel 文件的当前行索引,以免数据被覆盖。是否有任何特定的函数来获取填充的行数?